Hi Jason,
Your code has an built-in redundancy, in that in goes through each cell in
the range and setting the colour of that whole row if it meets the test
criteria. But as you set your range to the whole rows, the loop iterates
through each cell in the range, A2, B2, C2, etc. Thus A2 is tested and the
row is coloured, B2 is tested and the same row is coloured, C2 is tested and
the same row is coloured, etc.
This can be circumvented by changing
Set colorRng = Range("2:" & iLastRow)
to
Set colorRng = Range("A2:A" & iLastRow)
Regards
Bob
"Jason Morin" wrote in message
...
Try:
Sub ColorRows()
Dim iLastRow As Long
Dim colorRng As Range
Dim cell As Range
Application.ScreenUpdating = False
iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
Set colorRng = Range("2:" & iLastRow)
For Each cell In colorRng
With cell
If .Row Mod 2 = 0 Then
.EntireRow.Interior.ColorIndex = 3 'Red
'Blue=5,Green=10,Yellow=6
End If
End With
Next
Application.ScreenUpdating = True
End Sub
---
To use this macro, press ALT+F11, go to Insert Module,
and paste in the code in the window. Go back to XL (ALT+Q)
and run the macro under Tools Macro Macros.
HTH
Jason
Atlanta, GA
-----Original Message-----
I have worksheets with several hundred rows and want to
record a macro that
will highlight every other row, starting at row 2, until
the end. I can
record a macro to highlight several rows but how can I
repeat until the end
of the worksheet?
.
|