how do I compare the value of a cell to a different cell

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

How do I compare the value of A2 to A1 in a macro?

I have 7,000 rows of text. Many of lines have the same
information as previous lines. Ultimately, I want to
delete the rows with repeated information. (I know how to
do that.) But, I want to compare A2 to A1 to see if the
text is the same. If it's the same, I'll delete A2 and
then compare the (new) A2 to A1. If it's different, then
I'll move to A3 and compare that to A2, etc.

I figure it's got something to do with ActiveCell.Value
but I don't know how to refer to or evaluate
the "previous" cell within the macro command.

Thanks.
 
Try something like the following:

Dim CurRow, nextRow as integer
dim curRVal, nxtRVal as variant

curRow=1

for nextrow = 2 to 7000
curRVal=worksheets(1).cells(curRow,1).value2
nxtRVal=worksheets(1).cells(nextRow,1).value2
if(curRVal=nextRVal)then
'delete the row you want deleted
end if
next nextRow

I hope that helps!

Kevin
 
Thanks for trying, Kevin. Unfortunately, it doesn't seem
to work. The macro doesn't seem to recognize that the
values are equal and, thus, goes directly to the "End If."
 

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

Back
Top