Merge cells through a range

craigy111

New Member
Joined
Jul 5, 2017
Messages
20
I am hoping the Excel Gurus can help.

Using Excel 2007

I am looking to merge cells in a row through a range of columns:

Merge A6:H6
Merge J6:N6
Merge P6:S6

Then repeat the above for every 4th row for their respective cells.

Therefore i end up with A10:H10 merged etc etc

at the moment i have a mess of code:

Range("J6:n6").MergeCells = True
Range("J10:n10").MergeCells = True
Range("J14:n14").MergeCells = True
Range("J18:n18").MergeCells = True

This code is repeated for every merge.

Thanks in advance of any help
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
How far down (how many rows) do you want it to go down?
If it is dynamic, what is the logic for determining that?
Is there one column that will always have data in it that we can use to find the last row?
 
Upvote 0
So here is code that should do what you want. I currently have it hard-coded to go down as far as row 100.
I also added a calculation that I commented out that shows you how to have automatically go down to the last row in column A with data.
Code:
Sub MyMergeCells()

    Dim myRow As Long
    Dim lastRow As Long
    
'   Find/enter last row
    lastRow = 100
    'lastRow = Cells(Rows.Count, "A").End(xlUp).Row

    Application.ScreenUpdating = False
    
'   Loop through all rows, merging every 4th row
    For myRow = 6 To lastRow Step 4
        Range(Cells(myRow, "A"), Cells(myRow, "H")).MergeCells = True
        Range(Cells(myRow, "J"), Cells(myRow, "N")).MergeCells = True
        Range(Cells(myRow, "P"), Cells(myRow, "S")).MergeCells = True
    Next myRow
        
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,091
Members
453,021
Latest member
Justyna P

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