Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 130
  • Last Modified:

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.
0
K B
Asked:
K B
1 Solution
 
Bill PrewCommented:
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 LissRetired ProgrammerCommented:
I think Bill's line 5 should be

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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now