Hi All,
New to VBA and looking for some help. I want to hide columns based on multiple user selections.
For this example, if a user wants to filter by Fiscal Quarter, Q1, Q2 (Row 3 values from column F onwards).... and give them the option to filter by Fiscal Year, FY24, FY23.... (Row 4 values from Column F onwards).
I've figured out how to hide by one input, in this case Quarter, but looking for some help on how to include the second.
B3 = Q1, Q2, Q3, Q4, All
B4 = FY24, FY23, FY22, FY21, All
Private Sub Worksheet_Change(ByVal Target As Range)
Dim x As Variant, y As String
If Target.Address = "$B$3" Then
y = Target.Value
With Range("F3:FF3")
Application.ScreenUpdating = False
.EntireColumn.Hidden = (y <> "All")
If y <> "All" Then
For Each x In .Cells
If x = y Then x.EntireColumn.Hidden = False
Next
End If
Application.ScreenUpdating = True
End With
End If
End Sub
New to VBA and looking for some help. I want to hide columns based on multiple user selections.
For this example, if a user wants to filter by Fiscal Quarter, Q1, Q2 (Row 3 values from column F onwards).... and give them the option to filter by Fiscal Year, FY24, FY23.... (Row 4 values from Column F onwards).
I've figured out how to hide by one input, in this case Quarter, but looking for some help on how to include the second.
B3 = Q1, Q2, Q3, Q4, All
B4 = FY24, FY23, FY22, FY21, All
Private Sub Worksheet_Change(ByVal Target As Range)
Dim x As Variant, y As String
If Target.Address = "$B$3" Then
y = Target.Value
With Range("F3:FF3")
Application.ScreenUpdating = False
.EntireColumn.Hidden = (y <> "All")
If y <> "All" Then
For Each x In .Cells
If x = y Then x.EntireColumn.Hidden = False
Next
End If
Application.ScreenUpdating = True
End With
End If
End Sub