VBA Merge Adjacent Dynamic Cells

Small Paul

Board Regular
Joined
Jun 28, 2018
Messages
118
Hi

I suspect there is a simple answer to this but I cannot find it!

I have a sheet with a variable number of rows. I have totals at the bottom of columns J & K. I then have a combined total in column J - offset(0,2).

I need to merge the cell in J with the adjacent cell in K.

I have tried the following (and permutations thereof):

Code:
Range("J" & Rows.Count).End(xlUp).Offset(2, 0).FormulaR1C1 = "=SUM(R[-2]C10:R[-2]C11)"    
    'Range(cells(ActiveCell), cells(0, 1)).Merge
    Range(0, 0)(0, 1).Merge
    
    'For Each cl In Range("J1:K500")
    'If IsEmpty(cl.Offset(1)) Then
          'Range(Selection, Selection.End(xlDown)(0, 1)).Select
            'Selection.Merge
PLEASE, don't laugh at my attempts!!!!
Any guidance would be appreciated.

Thanks
Small Paul.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Perhaps.
Code:
Dim cl As Range

    For Each cl In Range("J1", Range("J" & Rows.Count).End(xlUp).Offset(-3))
        cl.Resize(, 2).Merge
    Next cl
Note, if there is any data in column K you will get warning messages about only keeping the data in the upper left cell, i.e. column J.
 
Upvote 0
Hi Norie

Thank you for the quick reply.
Unfortunately, it did merge the cells.
The cell in column K will always be empty.

Small Paul.
 
Upvote 0
When I put:
Code:
cl.Resize(, 2).Merge
into 'immediate' it is giving me a "Compile Error: Type mismatch" error
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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