VBA code for coloring alternate rows

This code will color the alternate rows in the sheet to blue and white. 

Sub ColorAlternateRows()
Dim i As Long, LastRow As Long
LastRow=ActiveSheet.Cells(Rows.Count,1).End(xlUp).Row
For i = 2 To LastRow
  If i Mod 2 = 0 Then
    ActiveSheet.Rows(i).Interior.Color =RGB(176, 224, 230)
  Else
    ActiveSheet.Rows(i).Interior.Color =RGB(255, 255, 255)
  End If
Next i
End Sub


Open the Visual Basic Editor, then paste the code into a new module. Once you have saved the module, you can run the macro by pressing `F5`

You can change the colors to whatever you want by changing the RGB values in the code.

Popular posts from this blog

Formula to Get Country Flags in Google Sheets

Steps to Turn On Offline Access for Google Docs, Sheets and Slides