Merge Cells Repeat

BeaglesBuddy

New Member
Joined
Mar 6, 2011
Messages
6
Is there a macro that can merge two cells in a column while deleting the value in the 2nd row. Right now when i merge those cells the 2nd value deletes automatically. I would like to automate this for the entire column.
Sorry if this has been asked already. I searched and couldn't find anything that applied with my lack of vb knowledge.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Place this code into a new module (Alt+F11, Insert>Module, Paste, then Alt+Q to return to Excel).
To run the macro select the first cell in the range, click Alt+F8, and double-click the macro name.

Code:
Sub MergeLoop()
    Application.DisplayAlerts = False
    Do Until IsEmpty(ActiveCell)
        ActiveCell.Resize(2, 1).Merge
        ActiveCell.Offset(1, 0).Select
    Loop
    Application.DisplayAlerts = True
End Sub

Denis
 
Upvote 0
Place this code into a new module (Alt+F11, Insert>Module, Paste, then Alt+Q to return to Excel).
To run the macro select the first cell in the range, click Alt+F8, and double-click the macro name.

Code:
Sub MergeLoop()
    Application.DisplayAlerts = False
    Do Until IsEmpty(ActiveCell)
        ActiveCell.Resize(2, 1).Merge
        ActiveCell.Offset(1, 0).Select
    Loop
    Application.DisplayAlerts = True
End Sub

Denis

This code worked perfectly for me! I would like to repeat this code on the next column from the same row that I started it initially (example: I started this macro with A3 as the active cell...I would like it to repeat starting on cell B3). I would like it to repeat for columns A-G (7 columns total - this will remain consistent). Is there a way to do this? I appreciate the help!
 
Upvote 0
Hi

Here is one way to extend the macro:
Code:
Sub MultiCol()
    Dim i As Long
    Const RwStart = 3
    
    For i = 1 To 7
        Cells(RwStart, i).Select
        MergeLoop
    Next i
End Sub


Sub MergeLoop()
    Application.DisplayAlerts = False
    Do Until IsEmpty(ActiveCell)
        ActiveCell.Resize(2, 1).Merge
        ActiveCell.Offset(1, 0).Select
    Loop
    Application.DisplayAlerts = True
End Sub

Replace the existing code with the new version above
While on the sheet where you want to merge the cells, press {Alt}+{F8} and run the MultiCol macro

MultiCol runs from columns A to G (that's the 1 to 7 values for i, in the declaration)
It starts at Row 3 (that's the RwStart constant)
To change the range and / or the starting row, adjust those values

Denis
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,608
Messages
6,120,500
Members
448,968
Latest member
screechyboy79

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