ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   comapring cell values (https://www.excelbanter.com/excel-programming/372987-comapring-cell-values.html)

nickm687

comapring cell values
 
Hi, i have a list on a worksheet (sheet1) which looks like this for
example. the list is in alphabetical order so any indentical cells are
next to each other.

AA
AA
AB
AB
AC
AC
AD
AG
AL
AM
AM

i am trying to write a macro which will go through each cell and
compare it with the next cell. if they are the same the second cell's
value is changed to an "*". i tried a couple of ways but everytime i
just crash excel.

the list would look like this after the macro was run.

AA
*
AB
*
AC
*
AD
AG
AL
AM
*


thanks in advance.

nick


Bob Phillips

comapring cell values
 
Sub test()
Dim iLastRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = iLastRow To 2 Step -1
If Cells(i,"A").Value = Cells(i-1,"A").Value Then
Cells(i,"A").Value = "*"
End If
Next i

End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"nickm687" wrote in message
ups.com...
Hi, i have a list on a worksheet (sheet1) which looks like this for
example. the list is in alphabetical order so any indentical cells are
next to each other.

AA
AA
AB
AB
AC
AC
AD
AG
AL
AM
AM

i am trying to write a macro which will go through each cell and
compare it with the next cell. if they are the same the second cell's
value is changed to an "*". i tried a couple of ways but everytime i
just crash excel.

the list would look like this after the macro was run.

AA
*
AB
*
AC
*
AD
AG
AL
AM
*


thanks in advance.

nick




nickm687

comapring cell values
 
ha works a treat. and you make it look simple.

thank you very much.


Bob Phillips wrote:
Sub test()
Dim iLastRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = iLastRow To 2 Step -1
If Cells(i,"A").Value = Cells(i-1,"A").Value Then
Cells(i,"A").Value = "*"
End If
Next i

End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"nickm687" wrote in message
ups.com...
Hi, i have a list on a worksheet (sheet1) which looks like this for
example. the list is in alphabetical order so any indentical cells are
next to each other.

AA
AA
AB
AB
AC
AC
AD
AG
AL
AM
AM

i am trying to write a macro which will go through each cell and
compare it with the next cell. if they are the same the second cell's
value is changed to an "*". i tried a couple of ways but everytime i
just crash excel.

the list would look like this after the macro was run.

AA
*
AB
*
AC
*
AD
AG
AL
AM
*


thanks in advance.

nick




All times are GMT +1. The time now is 02:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com