Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
FIND / SEARCH text compare cell to string in 3rd cell | Excel Discussion (Misc queries) | |||
Compare text string of a cell in Column A VS another cell in Colum | New Users to Excel | |||
Compare text string of a cell in Column A VS another cell in Colum | Excel Discussion (Misc queries) | |||
Compare text string of a cell in Column A VS another cell in Colum | Excel Worksheet Functions | |||
How do I compare cells and if FALSE compare to next cell in EXCEL | Excel Worksheet Functions |