VBA code to hide or unhide rows based on a cell value
Solution 1:
It looks like your code has some typos in it. You want something that is like this:
Sub PG1()
If Range("E50").Value = "Passed" Then
Rows("51:51").EntireRow.Hidden = True
ElseIf Range("E50").Value = "Failed" Then
Rows("51:51").EntireRow.Hidden = False
End If
End Sub
To have the row hide/unhide update as you change the sheet, put it in a Worksheet_Change
event:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("E50").Value = "Passed" Then
Rows("51:51").EntireRow.Hidden = True
ElseIf Range("E50").Value = "Failed" Then
Rows("51:51").EntireRow.Hidden = False
End If
End Sub
Solution 2:
there was no typo. "rows(51)" is valid. but you don't need the "entirerow" modifier
rows(n).hidden=true ; where n is an valid row number
to hide multiple rows
range(rows(n1),rows(n2)).hidden=true ; will hide rows n1 though n2