VBA code to merge every three rows starting from second row

alirezae90

New Member
Joined
Jan 20, 2019
Messages
8
Hi everyone,

I need a VBA code that would merge every three rows (if data exists) starting from row 2, and covering column range of A to lets say J.

Many thanks in advance,
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
To clarify, are you wanting to merge every third row, like A2, B2, C2... or are you wanting to merge groups of 3 rows, like A2, A3, A4, then B2, B3, B4?
 
Upvote 0
Try this

Code:
Sub Macro4()


    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    For i = 2 To Range("A" & Rows.Count).End(xlUp).Row 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
End Sub
 
Upvote 0
Thank you DanteArmor for the code. How would I modify this to include only columns C through F? I attempted the simpleton edit of replacing "A" with "C" and "J" with "F" in your code, but the merging still begins with column A (it did, however, stop at column F).
 
Upvote 0
Hi DanteAmor,

Yes this worked perfectly and thank very much. I completely forgot to report back here.

Thanks
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,664
Members
448,976
Latest member
sweeberry

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