I have created a toggle button to hide multiple non-adjacent columns. It works, but when I filter a column, the button stops working. The only way to get it to work again is if I re-sort the column I had filtered with, back to A-Z.
Is there a way to fix this? Is there some code I can add for it to reset after a filter is used?
The code I have set:
Private Sub ToggleButton1_Click()
Dim xAddress As String
Dim splitAddress As Variant
xAddress = "Q,S,U,W,Y,AA,AG,AI,AK,AU" 'change this to the column letters
splitAddress = Split(xAddress, ",")
If ToggleButton1.Value Then
For Each Var In splitAddress
Application.ActiveSheet.Columns(Var).Hidden = True
ToggleButton1.Caption = "Show Column"
Next Var
Else
For Each Var In splitAddress
Application.ActiveSheet.Columns(Var).Hidden = False
ToggleButton1.Caption = "Hide Column"
Next Var
End If
End Sub
Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
Bookmarks