Archive of Mr Excel Message Board


Back to Excel VBA archive index
Back to archive home

a toggle button on a userform

Posted by Jim on December 15, 2001 4:43 PM
Hi,

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

Re: a toggle button on a userform

Posted by Jacob on December 15, 2001 6:13 PM
Hi

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


Re: a toggle button on a userform

Posted by Ivan F Moala on December 16, 2001 12:58 AM
Jim
Not sure if this is what you meant...

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


This archive is from the original message board at www.MrExcel.com.
All contents © 1998-2004 MrExcel.com.
Visit our online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.