Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default how do I compare the value of a cell to a different cell

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default how do I compare the value of a cell to a different cell

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

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default how do I compare the value of a cell to a different cell

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


-----Original Message-----
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

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

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
FIND / SEARCH text compare cell to string in 3rd cell nastech Excel Discussion (Misc queries) 0 October 29th 07 02:51 AM
Compare text string of a cell in Column A VS another cell in Colum Tan New Users to Excel 2 August 1st 07 09:45 AM
Compare text string of a cell in Column A VS another cell in Colum Tan Excel Discussion (Misc queries) 1 August 1st 07 09:03 AM
Compare text string of a cell in Column A VS another cell in Colum Tan Excel Worksheet Functions 1 August 1st 07 09:01 AM
How do I compare cells and if FALSE compare to next cell in EXCEL Cindie Excel Worksheet Functions 0 March 24th 06 05:29 PM


All times are GMT +1. The time now is 09:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"