Comparing data in columns and delete if not equal
Hi,
This assumes the data you will compare begins in B1, which means there are
no Headers, if there are headers change the second line of the code from
"Range("B1").Select" to "Range("B2").Select.
Sub TwoColumns()
Range("B1").Select
Do Until ActiveCell.Value = ""
Column1 = ActiveCell.Value
Column2 = ActiveCell.Offset(0, 4).Value
If Column1 = Column2 Then
Else
ActiveCell.EntireRow.Delete
ActiveCell.Offset(-1, 0).Range("A1").Select
End If
ActiveCell.Offset(1, 0).Range("A1").Select
Loop
End Sub
Thanks,
"Robert" wrote:
Hello,
Do I need to replace the STOP with anything else?
My data is set this way.
ColA ColB ColC ColD ColE ColF
5/1/05 1 8 25 0.552 3
5/2/05 2 3 47 0.67 3
5/3/05 3 7 8 0.22 3
So for example, I need to compare column F with Column B and everytime there
is a common number in both columns I need to keep the whole row of data.
Otherwise I have to delete the row if Columns B and F dont match.
Hope it is more clearer now.
Thanks for the help.
Rob
"David" wrote:
Hi,
The stop can be removed sorry about that. Can you tell me how your data is
set up, which columns you are trying to compare? ie
ColA ColB ColC ColD ... etc
5 9 a z .....Etc
Then tell what you are comparing ColA and ColB or ColD and ColZ. It is set
up to start on the first value to compare and then compare it to the nest
column to the right, ie ColA and ColB or ColD and ColE.
Thanks,
"Robert" wrote:
Hi,
Im new to Macros and I was wondering if there is a simple macro to compare
two columns and see if they have the same value. If the columns dont match, I
need to delete the whole row.
Any guidance would be really appreciated.
Thanks
Rob
|