Compare two columns, delete rows that match?

J

jhonnyc377

Hello,

I would like to compare columns B and C, and, if they match for a given row,
delete or hide that row. B and C will be numbers (A is text) and as I am
new to development in general, I unfortunately have no code to post. Any
help would be much appreciated. Since this tool will be used by many
non-tech folks many times a day, would it be best as a macro? Standalone
..exe? Excel '07 addin? Thank you very much in advance for your help.
 
M

Mike H

Hi,

Right click the worksher name tab, view code and paste this in. At the end
of the code use whichever line you want, one hides the rows and the other
deletes them.

Sub stance()
Dim myrange, copyrange As Range
Lastrow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
Set myrange = Range("B1:B" & Lastrow)
For Each c In myrange
If c.Value = c.Offset(, 1).Value Then
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
'copyrange.EntireRow.Hidden = True
copyrange.Delete
End If
End Sub

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top