Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading