what's wrong?

  • Thread starter Thread starter active_x
  • Start date Start date
A

active_x

what's wrong?

Example:
------------------------------------------------------------------------------------Sub
combine_cells()
Dim rngContent As Range
Dim rLastContent As Integer
Dim i As Integer

rLastContent = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row

Set rngContent = Range("B4:G" & rLastContent)

Application.DisplayAlerts = False

For i = 4 To rLastContent
Range("B"&i&":"&"G"&i).Merge
Next

Application.DisplayAlerts = True

End Sub
------------------------------------------------------------------------------------The
above vba is supposed to run in this way:
merge B4:G4
merge B5:G5
merge B6:G6
...
However, NONE of the cells is merged! What's wrong? (question 1)
Can the vba be written in the form of: (question 2)
For Each ... In ...
...
Next
If yes, how to write? (question 3)
 
works for me though I had to put spaces in the .Merge line:

For i = 4 To rLastContent
Range("B" & i & ":" & "G" & i).Merge
Next

You do, of course, lose the data in columns C to G. Have you got data in
the cells on the sheet ? If the sheet is "new" then rLastContent will have
a value of 1 and hence the loop will not run.

Regards

Trevor
 
Back
Top