View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
nuge nuge is offline
external usenet poster
 
Posts: 5
Default Compare & Delete in Excel

Thanks!
Works like a charm!

"Tom Ogilvy" wrote in message ...
My mistake - there is a typo in Dave's code. Here is a revision:

Option Explicit
Sub testme01()

Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long
Dim res As Variant

With ActiveSheet
FirstRow = 1 'no headers in row 1???
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
For iRow = LastRow To FirstRow Step -1
res = Application.Match(.Cells(iRow, "B").Value, .Range("a:a"),
0)
If IsError(res) Then
'keep it--it's unique
Else
.Cells(iRow, "B").Delete shift:=xlShiftUp
End If
Next iRow
End With

End Sub


this line
.Cells(iRow, "B").Delete shift:=xlShiftUp

originally was

.Cells(res, "B").Delete shift:=xlShiftUp