Archive of Mr Excel Message Board
I'm trying to use a toggle button to hide rows then
show rows it will hide or show but i haven't been able
to do both. Any help would be appreciated.
Thanks, Jim

| Check out our Excel VBA Resources | ||||
![]() |
![]() |
![]() |
![]() |
![]() |
This should get you started.
Sub test()
Dim MyRange
MyRange = InputBox("What range do you want hide?")
Range(MyRange).Select
Selection.EntireColumn.Hidden = True
End Sub
That will hide you inputted range, to unhide just change the code a bit. Attach the code to your userform buttons and you are set.
Jacob

Private Sub ToggleButton1_Click()
If ToggleButton1.Value = False Then
Range("a1:f1").EntireColumn.Hidden = False
ToggleButton1.Caption = "Hide Columns"
Else
Range("a1:f1").EntireColumn.Hidden = True
ToggleButton1.Caption = "Show Columns"
End If
End Sub
It assumes your toggle button shows and hides
columns..change to rows for rows.
So when you click on it it should Hide/Show
depending on the state of the Togglebutton value
which is either true or false.
Ivan
