Solved

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

Posted on 2016-08-04
2
106 Views
Last Modified: 2016-08-05
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
Comment
Question by:K B
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 56

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 41743297
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
 
LVL 48

Expert Comment

by:Martin Liss
ID: 41743335
I think Bill's line 5 should be

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

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use Windows Task Scheduler to print a Word document weekly so your printer ink won't dry out.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question