Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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/ |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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/ |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
What is wrong with my UDF | Excel Discussion (Misc queries) | |||
Insert Calculated Field (wrong Qty*Price = wrong Amount) | Excel Discussion (Misc queries) | |||
What Am I Doing Wrong | Excel Discussion (Misc queries) | |||
wHAT AM i DOING wrong | Excel Worksheet Functions | |||
What's wrong with this vb? | Excel Worksheet Functions |