Home > Software engineering >  Highlight Row in VBA
Highlight Row in VBA

Time:09-27

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

CodePudding user response:

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
  • Related