Hey All,
I have the following code which does what I want.: Hide columns dependent on the input in a cell. I want this to work in all the worksheets. I have only just started playing around with VBA and from reading a few posts this could be done with a loop function but I'm not sure my code is in the correct form...
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count = 1 And Target.Address = "$G$26" Then
If LCase(Target.Value) = "5" Then
Columns("O:AH").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "10" Then
Columns("O:AH").EntireColumn.Hidden = False
Columns("T:AH").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "15" Then
Columns("T:AH").EntireColumn.Hidden = False
Columns("Y:AH").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "20" Then
Columns("Z:AG").EntireColumn.Hidden = False
Columns("AD:AH").EntireColumn.Hidden = True
ElseIf LCase(Target.Value) = "25" Then
Columns("AD:AH").EntireColumn.Hidden = False
Else
Columns("B:M").EntireColumn.Hidden = False
End If
End If
End Sub
Any advice on how to get this to work across all the sheets would be greatly appreciated
Bookmarks