Thread: what's wrong?
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Trevor Shuttleworth Trevor Shuttleworth is offline
external usenet poster
 
Posts: 1,089
Default what's wrong?

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



"active_x" wrote in message
...
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)



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/