Sub JAN()
On Error GoTo ErrorHandler
With Sheet1
' Unprotect sheet if protected
If .ProtectContents Then .Unprotect Password:="YourPassword"
' Update shapes visibility
UpdateShapeVisibility .Shapes, "JANOn", True
UpdateShapeVisibility .Shapes, "JANOff", False
' Set other months' shapes to off
Dim months As Variant
months = Array("FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC")
Dim i As Long
For i = LBound(months) To UBound(months)
UpdateShapeVisibility .Shapes, months(i) & "On", False
UpdateShapeVisibility .Shapes, months(i) & "Off", True
Next i
' Show relevant columns
.Range("B:N").EntireColumn.Hidden = False
.Range("O:FM").EntireColumn.Hidden = True
' Highlight the selected tab
.Tab.Color = RGB(255, 255, 0) ' Highlight in yellow
' Reprotect the sheet
.Protect Password:="YourPassword"
End With
Exit Sub
ErrorHandler:
MsgBox "An error occurred: " & Err.Description, vbCritical
Err.Clear
End Sub
Sub FEB()
On Error GoTo ErrorHandler
With Sheet1
' Unprotect sheet if protected
If .ProtectContents Then .Unprotect Password:="YourPassword"
' Update shapes visibility
UpdateShapeVisibility .Shapes, "FEBOn", True
UpdateShapeVisibility .Shapes, "FEBOff", False
' Set other months' shapes to off
Dim months As Variant
months = Array("JAN", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC")
Dim i As Long
For i = LBound(months) To UBound(months)
UpdateShapeVisibility .Shapes, months(i) & "On", False
UpdateShapeVisibility .Shapes, months(i) & "Off", True
Next i
' Show relevant columns
.Range("O:FM").EntireColumn.Hidden = False
.Range("B:N").EntireColumn.Hidden = True
' Highlight the selected tab
.Tab.Color = RGB(255, 255, 0) ' Highlight in yellow
' Reprotect the sheet
.Protect Password:="YourPassword"
End With
Exit Sub
ErrorHandler:
MsgBox "An error occurred: " & Err.Description, vbCritical
Err.Clear
End Sub
' Helper Sub to Update Shape Visibility
Sub UpdateShapeVisibility(Shapes As Shapes, ShapeName As String, VisibleState As Boolean)
On Error Resume Next
If Not Shapes(ShapeName) Is Nothing Then
Shapes(ShapeName).Visible = IIf(VisibleState, msoCTrue, msoCFalse)
End If
On Error GoTo 0
End Sub