View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default compare two worksheets and delete rows

bgeier,

Not to usurp any credit from Tom, nor to "show him up", but this may
work.


Don't give it a second thought. We are all working to help the user and any
meaningful contribution is most welcome.

In that same vein, here is an implementation of my code using your method
that actually does work. I restricted it to look in only column A of the
second sheet based on what the OP originally posted.


Sub AAEE()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim i As Long
Set sh2 = Worksheets(2)
Set sh1 = Worksheets(1)
lastrow = sh1.Cells(Rows.Count, "A").End(xlUp).Row
For i = lastrow To 1 Step -1
Set rng = sh2.Columns(1).Find( _
sh1.Cells(i, "A").Value, sh2.Cells(Rows.Count, 1), _
xlFormulas, xlWhole, xlByColumns, _
xlPrevious, False)
If Not rng Is Nothing Then
sh1.Rows(i).Delete
End If
Next

End Sub

--
Regards,
Tom Ogilvy

"bgeier" wrote in
message ...

Not to usurp any credit from Tom, nor to "show him up", but this may
work.

Replace
If sh1.Cells(i, "A").Value = sh2.Cells(i, "A").Value Then

with
If sh1.Cells(i, "A").Value = Cells.Find(sh1.Cells(i, "A").Value,
ActiveCell, xlFormulas, xlWhole, xlByColumns, xlPrevious, False, False)
Then

This should search the entire sheet2 to find the value on sheet1


--
bgeier
------------------------------------------------------------------------
bgeier's Profile:

http://www.excelforum.com/member.php...o&userid=12822
View this thread: http://www.excelforum.com/showthread...hreadid=545996