Merging Cells In VBA

ConfuzzledThomas

New Member
Joined
Nov 28, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi everyone.

I have some data in column A from row number 12 to row number 62.

I want to merge the value in each row with the cell to the right of it.

So I want to merge A12 & B12, then A13 & B13 and so on.

The code I have now doesn't generate any errors but simply doesn't do anything.

Any help appreciated
VBA Code:
Dim k As Long
For k = 12 To 62    
Sheets("Clearance Instruction Document").Activate
Range(Cells(k, 1), Cells(k, 2)).Select
Selection.Merge
Sheets("Clearance Instruction Document").Activate
Range(Cells(k, 3), Cells(k, 4)).Select
Selection.Merge
Next k

Thanks in advance, Thomas
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
While merging is rarely necessary and something that most would advise against doing your code should work fine (it worked when I tried it in case I was missing something).
See if this variation to your code works instead, although I can see no reason why it would if yours is not.
Excel Formula:
Dim k As Long
With Sheets("Clearance Instruction Document")
    For k = 12 To 62
        .Range(.Cells(k, 1), .Cells(k, 2)).Merge
        .Range(.Cells(k, 3), .Cells(k, 4)).Merge
    Next k
End With
 
Upvote 0
Solution
While merging is rarely necessary and something that most would advise against doing your code should work fine (it worked when I tried it in case I was missing something).
See if this variation to your code works instead, although I can see no reason why it would if yours is not.
Excel Formula:
Dim k As Long
With Sheets("Clearance Instruction Document")
    For k = 12 To 62
        .Range(.Cells(k, 1), .Cells(k, 2)).Merge
        .Range(.Cells(k, 3), .Cells(k, 4)).Merge
    Next k
End With
Thank you that seems to work. I know what you mean about merged cells they are a complete pain. However, I have just been tasked with automating this particular document for a work group.
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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