ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Colour rows based on value (https://www.excelbanter.com/excel-programming/428200-colour-rows-based-value.html)

Martin

Colour rows based on value
 
Hello,

I have this code that almost works but just need some help. This looks at
the value of each row, column 3 and colours the entire row with shade 36 if
the cell value is different to the row above (still column 3). However when
the change takes place in column 3 it doesnt shade that row but it shades all
others. So I am almost there but stumped why it does this.

Can anyone help?

Dim lRow As Long
Dim lCol As Long

For lRow = 2 To 9216

If Cells(lRow, 3).Value = Cells(lRow - 1, 3) Then
If IsEmpty(Cells(lRow, 256)) Then
lCol = Cells(lRow, 256).End(xlToLeft).Column
Else
lCol = 256
End If
Range(Cells(lRow, 1), Cells(lRow, lCol)).Interior.ColorIndex = 36
End If
Next

Thanks


All times are GMT +1. The time now is 02:06 PM.

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