Hi experts,
So I have this code, which works like a charm for its intended purpose:
However, I would like to have a "sub-version" of this that would then be tied to a button. Other than being a sub and not a worksheet change, it'd also have to either include more target addresses, or, alternatively, also target values that are within -2 of the If Target.Address = "$G$17". E.g. if the
Is set to 5, it'd have to also target headers with 4 and 3 - if that makes sense.
Any tips, tricks or help would be greatly appreciated.
So I have this code, which works like a charm for its intended purpose:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Sort planning based on week
Dim cel As Range, Headers As Range
Dim s As String
Set Headers = Range("i1:ABJ1")
If Target.Address = "$G$17" Then
s = Target.Value
Application.ScreenUpdating = False
If s = "" Then
Headers.EntireColumn.Hidden = False
Else
For Each cel In Headers
cel.EntireColumn.Hidden = Not cel.Value = s
Next cel
End If
Application.ScreenUpdating = True
End If
End Sub
However, I would like to have a "sub-version" of this that would then be tied to a button. Other than being a sub and not a worksheet change, it'd also have to either include more target addresses, or, alternatively, also target values that are within -2 of the If Target.Address = "$G$17". E.g. if the
VBA Code:
If Target.Address = "$G$17"
Any tips, tricks or help would be greatly appreciated.