I’m new to both VBA and this forum, so forgive me if I’ve committed any blunders. On a daily basis I receive a spreadsheet with the strings “Yes” and “No” in the cells of Column X. I would like to hide Column X if it contains any value other than Yes. What I’ve got below will run in my test spreadsheet, but it hides both the column it’s supposed to hide and the one it’s not. I’m not sure why it’s not recognizing the Yes string. Thanks for your help!
Code:
Sub Hide()
Application.ScreenUpdating = False
Dim Y, N As String
Y = "Yes"
N = "No"
For Each Cell In Range("X2:X1000")
If Cell.Value = "" Or Cell.Value = N Then
Cell.EntireColumn.Hidden = True
ElseIf Cell.Value <> "" And Cell.Value = Y Then
Cell.EntireColumn.Hidden = False
End If
Next Cell
Application.ScreenUpdating = False
End Sub