I have created several worksheets with VBA code that hide columns that are not referenced in a drop down list of months.
Try a workbook level change event.
Private Sub Workbook_SheetChange(ByVal sh As Object, ByVal Target As Range)
Dim sWorkSheets$, StartColumn&, LastColumn&, iRow&, sHts, ws As Worksheet, s%, i&
sWorkSheets$ = "Sheet1,Sheet2,Sheet3"
StartColumn = 1
LastColumn = 13
iRow = 1
If Target.Address = "$B$3" And InStr(sWorkSheets, sh.Name) > 0 Then
Application.ScreenUpdating = False
Application.EnableEvents = False
sHts = Split(sWorkSheets, ",")
For s = 0 To UBound(sHts)
Set ws = Nothing
On Error Resume Next
Set ws = Sheets(sHts(s))
On Error GoTo 0
If Not ws Is Nothing Then
ws.Unprotect
For i = StartColumn To LastColumn
With ws.Cells(iRow, i)
.EntireColumn.Hidden = .Value = "X"
End With
Next i
ws.Protect
End If
Next
End If
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Bookmarks