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

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.
LVL 8
K BAsked:
Who is Participating?
 
Bill PrewConnect With a Mentor 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
0
 
Martin LissOlder than dirtCommented:
I think Bill's line 5 should be

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

From novice to tech pro — start learning today.