PC Review


Reply
Thread Tools Rate Thread

Compare two columns, delete rows that match?

 
 
jhonnyc377
Guest
Posts: n/a
 
      24th Apr 2008
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.

 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      24th Apr 2008
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

"jhonnyc377" wrote:

> 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.
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare cells and copy columns after match Kcope8302 Microsoft Excel Worksheet Functions 2 5th Aug 2009 05:37 PM
compare rows for a match and sum the matches Bert Microsoft Excel Worksheet Functions 1 30th Apr 2009 09:27 PM
How to compare two columns of data to make sure they match Len Microsoft Excel Worksheet Functions 0 24th Jun 2008 04:07 PM
Compare columns, delete the rows that DO match. =?Utf-8?B?cnlndXk3Mjcy?= Microsoft Excel Programming 2 20th May 2007 04:34 PM
Want to compare two columns and then fill with data from the match =?Utf-8?B?TmVlZHkgQw==?= Microsoft Excel Worksheet Functions 1 11th Jan 2006 04:52 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:40 PM.