The following code hides columns with the text value in the code. How could I make the code to hide all the columns that do not match the value in cell “G1â€.
Suppose I write “January" in “G1â€. I want all the columns that do not contain the Month "January" to be hidden.
Code: Select all
Sub HideColumns()
Application.ScreenUpdating = False
Dim c As Range
For Each c In Range("A2:E2")
c.EntireColumn.Hidden = (c.Value = "January")
Next c
Application.ScreenUpdating = True
End Sub