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

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
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
 

Forum statistics

Threads
1,147,846
Messages
5,743,521
Members
423,801
Latest member
paulj4177

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
Top