VBA to Merge Cells in Excel 365

edward233

Board Regular
Joined
Jul 4, 2002
Messages
66
Hi all
I'm trying to use VBA code to merge rows in sheet1 using a certain Column. So what i have is lets say i want to merge rows in
Column C starting at row 5 to row 9, then move to Column d starting at row 5 to row 10, them move to Column d starting at row 5 to row 10.
Then do the same thing starting at row 10 to row 14, starting at row 10 to row 14, starting at row 10 to row 14,
Also the number of columns will change depending how many the user picks. I have a cell named merge_1 in sheet1. witch is my input cell.



Thanks Edward
 
Yes, very easy to loop through if there's a pattern. For example, this will merge C5:C9, C10:C14, C15:C19 and C20:C24.

VBA Code:
With Worksheets("Sheet1")
    For i = 5 To 20 Step 5
        .Range("C" & i).Resize(5).Merge
    Next i
End With

But beware, merged cells can create many problems. I never use them myself, and I have a keyboard shortcut to remove them from any workbooks that I need to review.
 
Upvote 0

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