Duplicate Rows in VBA

masterlodi

New Member
Joined
Jan 13, 2005
Messages
3
I have a worksheet such as this

Column A Column B Column C
CompanyName John Time
CompanyName John Time
CompanyName John Time
CompanyName John Time <-- need this row
CompanyName Dave Time
CompanyName Dave Time
CompanyName Dave Time
CompanyName Dave Time <-- need this row

etc etc

How can I (using VBA) delete all but the last row for each person?

Any help is greatly appreciated.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi

try the code
Code:
Sub test()
Dim dic As Object, i, x
Set dic = CreateObject("scripting.dictionary")
With ActiveSheet
    For i = .Range("b65536").End(xlUp).Row To 1 Step -1
        If Not dic.exists(.Cells(i, 2).Value) Then
            dic.Add .Cells(i, 2).Value, i
        End If
    Next
    x = dic.items
    For i = LBound(x) To UBound(x)
        .Cells(x(i), 1).Resize(1, 3).Copy _
        Destination:=.Range("h" & .Range("h65536").End(xlUp).Row + 1)
    Next
End With
Set dic = Nothing
Erase x
End Sub

assuming the original data starts from A1

hope this helps

jindon
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,588
Members
449,089
Latest member
Motoracer88

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