Merge adjacent cells in VBA
Hello friends! Today we’ll be learning to merge adjacent cells with same values in VBA(as shown in image below).
Use the reusable code below
Sub merge()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
'------Select Range
Set myRange = Range("B2:L2")
'------Merge
CheckAgain:
For Each i In myRange
If i.Value = i.Offset(0, 1).Value And Not IsEmpty(i) Then
Range(i, i.Offset(0, 1)).merge
i.HorizontalAlignment = xlCenter
GoTo CheckAgain
End If
Next
End Sub
Keep visiting Analytics Tuts for more tutorials.
Thanks for reading! Comment your suggestions and queries