Excel VBA

css navigation by Css3Menu.com

Odd and Even Rows

I had a large spreadsheet with over 1600 rows of information that I wanted to highlight alternating sections. If the first row of the section is an Odd number, color to background; otherwise, leave default.
Sub MakPretty()
    Dim X As Long
    Application.ScreenUpdating = False
    For X = 5 To 1648 Step 3   'My rows are in groups of 3
    Cells(X + 2, 13) = "=" & Cells(X + 2, 12).Address & "/34"
    If Len(Cells(X, 1)) > 0 Then
        Cells(X, 1).Interior.ColorIndex = 6
    End If
        Select Case X Mod 2    'If the row is not divisible by 2 i.e. Odd
            Case 1
                Range(Cells(X, 2), Cells(X + 2, 13)).Select
                Selection.Interior.ColorIndex = 40
            Case Else
        End Select
    Next
    Application.ScreenUpdating = True
End Sub

It happened that the 3rd row of each section needed a computation in the last column.

For the 1600 or so rows, the process is almost instantaneous.


© 2005-2024

Updated:  06/21/2024 07:42
This page added:  06 January 2005