Excel VBA: Alternate Row Colors in Range

calendar_today Asked Jan 7, 2011
thumb_up 7 upvotes
history Updated April 16, 2026

Question posted 2011 · +6 upvotes

I spent a VERY long time today looking up a method to alternate row colors within a specified range. There really isn’t a lot out there and to be honest what I found just looked over-complicated. So, I decided to stop acting like a shameless ‘script-kiddy’ and put the below sample together:

Sub AlternateRowColors()
Dim lastRow as Long

lastRow = Range("A1").End(xlDown).Row

For Each Cell In Range("A1:A" & lastRow) ''change range accordingly
    If Cell.Row Mod 2 = 1 Then ''highlights row 2,4,6 etc|= 0 highlights 1,3,5
        Cell.Interior.ColorIndex = 15 ''color to preference
    Else
        Cell.Interior.ColorIndex = xlNone ''color to preference or remove
    End If
Next Cell

End Sub

Now I know that works, but I was wondering if there’s a simpler method?

If so, please do tell because I’m very eager to learn simplification as I have a tendency to write verbose code at present. If not, then may this entry find it’s way to page 1 of Google for it’s search term(s), because it took me absolutely ages to find anything even remotely useful.


Comments left for script-kiddies’ benefit.

The following lines of code may be removed if your data contains no pre-exisiting colors:

    Else
        Cell.Interior.ColorIndex = xlNone

Accepted answer +7 upvotes

Alternating row colors can be done using conditional formatting:

screen capture

Top excel-vba Q&A (6)

+7 upvotes ranks this answer #101 out of 136 excel-vba solutions on this site .