Excel Macro: Delete a Row if Column A and B match (in that Row)

K B
K B used Ask the Experts™
on
Header           A              B
Row1             Joe          Frank
Row2             Bob         Bob
Row3             Bill          Owen
Row4             Kelly       Kelly


The macro would delete Rows #2  and  #4

Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Test your restores, not your backups...
Top Expert 2016
Commented:
Here is a pretty simple approach, see if this meets your needs.

Public Sub CleanUp()
   Application.ScreenUpdating = False
   With ActiveSheet
      For i = .Cells(.Rows.Count, 1).End(xlUp).Row To 2 Step -1
         If Cells(i, "B").Value = Cells(i, "C").Value Then
             .Rows(i).Delete
         End If
      Next
   End With
   Application.ScreenUpdating = True
End Sub

Open in new window

~bp
Martin Liss"There is still no cure for the common birthday." ~John Glenn
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
I think Bill's line 5 should be

 If Cells(i, "A").Value = Cells(i, "B").Value Then

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial