![]() |
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. |
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. . |
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. . . |
All times are GMT +1. The time now is 11:30 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com