Nan
Nan

Reputation: 61

Highlight Row in VBA

I have a problem where I need to highlight the entire row with the active cell. This row needs to be highlighted with a list of colors that have a certain colorIndex like 1,2,3,4. Each time the sub is run the highlighted row should change to one of these colors so that after the sub is run 4 times each color in the colorIndex has been the highlighted color once. I know how to highlight a row once and that code is below. Any ideas of what I should be looking to do to solve this?

Option Explicit

Sub highlightRow()
ActiveCell.EntireRow.Select
Selection.Interior.Color = 5
End Sub

Upvotes: 0

Views: 439

Answers (1)

milo5m
milo5m

Reputation: 619

This should do the trick

Sub highlightRow()
    With ActiveCell.EntireRow.Interior
        Select Case .ColorIndex
            Case 1 To 3: .ColorIndex = .ColorIndex + 1
            Case 4: .ColorIndex = 1
            Case Else: .ColorIndex = 1
        End Select
    End With
End Sub

Upvotes: 1

Related Questions