I have 3 tabs within my workbook that I would like to hide columns based on cell value. The following code hides some of the columns, but I am looking for assistance to add the rest of the columns. Here is what I am looking for:
Hide Columns J:M if cell K18 is ""
Hide Columns N:Q if cell O18 is ""
Hide Columns R:U if cell S18 is ""
Hide Columns V:Y if cell W18 is ""
Hide Columns Z:AC if cell AA18 is ""
Hide Columns AD:AG if cell AE is ""
Current code:
I am sure there is a better way to write this code so I am open to any suggestions.
Thanks!
Hide Columns J:M if cell K18 is ""
Hide Columns N:Q if cell O18 is ""
Hide Columns R:U if cell S18 is ""
Hide Columns V:Y if cell W18 is ""
Hide Columns Z:AC if cell AA18 is ""
Hide Columns AD:AG if cell AE is ""
Current code:
Code:
Sub HideColumnsSummary()
Dim wsMySheet As Worksheet
Application.ScreenUpdating = False
For Each wsMySheet In ThisWorkbook.Sheets
Select Case wsMySheet.Name
Case Is = "Summary 1", "Summary (2)", "Summary (3)"
With wsMySheet
If .Range("K18").Value = "" Then
Columns("J:M").EntireColumn.Hidden = True
Else
Columns("J:M").EntireColumn.Hidden = False
End If
End With
End Select
Next wsMySheet
Application.ScreenUpdating = True
End Sub
I am sure there is a better way to write this code so I am open to any suggestions.
Thanks!