PDA

View Full Version : VBA Merging duplicate -cells issue



malleshg24
07-28-2019, 01:03 PM
-Hi Team

Please assist in merging Duplicate cells
-Column B and A . Column b -contains names in -ascending order.
and -Column A Contains count of duplicate value from columnnB


Attached are my workbook.& expected result In column EF








Thanks
mg

mana
07-31-2019, 02:30 AM
Sub MergeCells2()
Dim ws As Worksheet
Dim lRow As Long
Dim i As Long

Set ws = Sheet1
lRow = ws.Cells(Rows.Count, "A").End(xlUp).Row

Application.DisplayAlerts = False

For i = lRow To 3 Step -1
If ws.Cells(i, 2) = ws.Cells(i - 1, 2) Then
ws.Cells(i - 1, 1).Resize(2).Merge
ws.Cells(i - 1, 2).Resize(2).Merge
End If
Next i

Application.DisplayAlerts = True

End Sub

malleshg24
07-31-2019, 04:21 PM
Hi Mana,

Superb :thumb!!! It worked as expected, you covered both column merging in a single loop thats awesome:clap:

Thanks a lot

regards,
mg