VBA code to Merge two rows (if it isn't empty) starting from 2nd row up to a limit (for columns A,B,C,D,E,F,G,H)

amaresh achar

Board Regular
Joined
Dec 9, 2016
Messages
108
Office Version
  1. 365
Platform
  1. Windows
Hello... I came across the following post similar to mine... But I need a minor tweak... i.e. It should stop merging operation up to a row limit (say row 1034)


Can anyone please help me with this...??

Thanks in advance...
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
If you are talking about the code Dante posted there, here is how to modify it to stop at row 1034:
VBA Code:
Sub Macro4()

    Dim lr As Long
   
'   Find last row in column A with data
    lr = Range("A" & Rows.Count).End(xlUp).Row
   
'   Cap lr at 1034
    If lr > 1034 Then lr = 1034

    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    For i = 2 To lr Step 3
        For j = 1 To Columns("J").Column
            With Range(Cells(i, j), Cells(i + 2, j))
                .HorizontalAlignment = xlCenter
                .VerticalAlignment = xlCenter
                .MergeCells = True
            End With
        Next
    Next

    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
   
End Sub
 
Upvote 0
Solution
If you are talking about the code Dante posted there, here is how to modify it to stop at row 1034:
VBA Code:
Sub Macro4()

    Dim lr As Long
  
'   Find last row in column A with data
    lr = Range("A" & Rows.Count).End(xlUp).Row
  
'   Cap lr at 1034
    If lr > 1034 Then lr = 1034

    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    For i = 2 To lr Step 3
        For j = 1 To Columns("J").Column
            With Range(Cells(i, j), Cells(i + 2, j))
                .HorizontalAlignment = xlCenter
                .VerticalAlignment = xlCenter
                .MergeCells = True
            End With
        Next
    Next

    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
  
End Sub
Thank You Sir... Working great....!!!
 
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,559
Members
449,171
Latest member
jominadeo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top