I would like to set up a spreadsheet that, when you click a button, looks the cells in column 4, 7, and 8 in each row and if the criteria of the three cells is correct, the entire row highlights. If the criteria is not correct I want to hide the incorrect rows.
I seem to be getting stuck where the code selects the row to highlight. I had tried using ActiveCell.EntireRow.Interior.Color but it only ever either highlights everything in the range or highlights the row of whatever cell was selected before clicking the button.
Private Sub CommandButton1_Click()
Dim rng As Range: Set rng = Application.Range("A5:I54")
Dim cell As Range
Dim row As Range
Dim i As Integer
For i = 1 To rng.Rows.Count
If rng.Cells(RowIndex:=i, ColumnIndex:=4).Text = "Yes" And rng.Cells(RowIndex:=i, ColumnIndex:=7).Text = "Yes" And rng.Cells(RowIndex:=i, ColumnIndex:=8).Text = "No" Then
rng.EntireRow.Interior.Color = vbYellow
ElseIf rng.Interior.ColorIndex = vbWhite Then rng.EntireRow.Hidden = True
End If
Next
End Sub
How can I get the code to recognise the criteria of the row and highlight it correctly?