i want to delete duplicate items in a list using code.

G

Guest

I have a dynamic list of 2 columns wide in alphabetical order(all items are
text). The first column contains many different duplicate items (these are
together as its in alpha order), the second column's items are all unique. I
wish to delete the first of each of the duplicate items and close all gaps in
order to reduce the length of the list. I am using Excel 2002.
 
T

Tom Ogilvy

Sub aa()
Dim lastrow As Long
Dim i As Long
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 2 Step -1
If Cells(i, 1).Value = Cells(i - 1, 1).Value Then
Cells(i, 1).Delete Shift:=xlShiftUp
End If
Next

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top