Forum Discussion

Vimal_Gaur's avatar
Vimal_Gaur
Brass Contributor
Jan 18, 2023
Solved

Excel VBA Conditional formatting

I have a sheet containing HEADINGS & STATUS The Headings contains particulars of a person The Status shows Yes or No   Condition1: if all Yes then highlight entire row in GREEN Condition2: if al...
  • OliverScheurich's avatar
    Jan 18, 2023

    Vimal_Gaur 

    Sub rowcolor()
    
    Dim i, j, k As Long
    
    For i = 3 To 22
    j = Application.WorksheetFunction.CountIf(Range(Cells(i, 10), Cells(i, 15)), "yes")
    
    If j = 6 Then
    Rows(i).Interior.ColorIndex = 4
    Else
    k = Application.WorksheetFunction.CountIf(Range(Cells(i, 10), Cells(i, 15)), "no")
    
    If k = 6 Then
    Rows(i).Interior.ColorIndex = 3
    Else
    Rows(i).Interior.ColorIndex = 6
    End If
    
    End If
    
    Next i
    
    End Sub

    An alternative could be these lines of code. In the attached file you can run the macro for conditional formatting.

Resources