This post will guide you how to merge adjacent cells in columns with same value or data with VBA Macro in Excel. How do I merge cells when adjacent value is the same in one column in Excel.
Merge Adjacent Cells with Same Data
Assuming that you have a list of data in range A1:B4, and you only want to merge adjacent cells in column A. How to do it. You can use an Excel VBA Macro to quickly merge adjacent cells with same data or value in a specific column or range. Just do the following steps:
#1 open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.
#2 then the “Visual Basic Editor” window will appear.
#3 click “Insert” ->”Module” to create a new module.
#4 paste the below VBA code into the code window. Then clicking “Save” button.
Sub MergeAdjacentCells() Application.ScreenUpdating = False Application.DisplayAlerts = False Set myRange = Application.Selection Set myRange = Application.InputBox("Select one Range that you want to merge cells with same data in one column:", "MergeAdjacentCells", myRange.Address, Type:=8) MergeAgain: For Each myCell In myRange If myCell.Value = myCell.Offset(1, 0).Value And IsEmpty(myCell) = False Then Range(myCell, myCell.Offset(1, 0)).Merge GoTo MergeAgain End If Next Application.DisplayAlerts = True Application.ScreenUpdating = True End Sub
#5 back to the current worksheet, then run the above excel macro. Click Run button.
#6 Select one Range that you want to merge cells with same data in one column. Click Ok button.
#7 let’s see the result:
Leave a Reply
You must be logged in to post a comment.