Merge every other two rows

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
774
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Good evening, I'm try to merge two rows beginning on Row 5 and only in Column J which will run to the bottom of the worksheet.

I found something and twisted to the code below, but I'm entirely off the mark. Any assistance would be greatly appreciated.
VBA Code:
Sub Merge_Column_J()
Dim RgToMerge As Range

For i = 5 To ActiveSheet.Cells(Rows.Count, 3).End(xlUp).Row Step 2

    Set RgToMerge = Range(Cells(i, 10), Cells(i + 1, 10))
    With RgToMerge
        .Merge
        .HorizontalAlignment = xlCenterAcrossSelection
        .VerticalAlignment = xlCenter
    End With

Next i
End Sub
 
Last edited by a moderator:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
I always shudder when I seem people merging cells (merged cells are just about the worst feature of Excel, and cause all sort of problems for things like VBA, sorting, etc).
But I digress...

Your code looks fine to me. How is it not working?

Perhaps your issue is here:
Rich (BB code):
ActiveSheet.Cells(Rows.Count, 3).End(xlUp).Row
Note that this is finding the last row in the third column (column C) with data, and going down that far.
Is that the intended column you want to look at to find the last row of data?
If not, change the number 3 to the column number you wish to use for that purpose.
 
Upvote 0
Solution
I always shudder when I seem people merging cells (merged cells are just about the worst feature of Excel, and cause all sort of problems for things like VBA, sorting, etc).
But I digress...

Your code looks fine to me. How is it not working?

Perhaps your issue is here:
Rich (BB code):
ActiveSheet.Cells(Rows.Count, 3).End(xlUp).Row
Note that this is finding the last row in the third column (column C) with data, and going down that far.
Is that the intended column you want to look at to find the last row of data?
If not, change the number 3 to the column number you wish to use for that purpose.
Thank you, after a struggle it is working now. Thank you,
 
Upvote 0
You are welcome.
Glad I was able to help.
 
Upvote 0

Forum statistics

Threads
1,223,881
Messages
6,175,161
Members
452,615
Latest member
bogeys2birdies

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