quick one?code for toggle button?!...stupid things

nadirv8

New Member
Joined
Sep 12, 2006
Messages
9
Erm... lost! How do I get toggle buttons to work. From what I can gather, VB needs to know what to do when the button is pressed down or lifted up. How to I formulate it?

This is what happens when I press it down:

Code:
Private Sub ToggleButton1_Click()
    Sheets("Holland").Select
    Range("D:D,H:H,L:L,P:P,T:T,X:X,AB:AB,AF:AF,AJ:AJ,AN:AN,AR:AR,AV:AV").Select
    Range("AV1").Activate
    Selection.EntireColumn.Hidden = False
    Sheets("Holland").Select
    Range("A1").Select
End Sub


How do I get it to "..hidden = True" to work when I lift the button?

Thankyou :)
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

DominicB

Well-known Member
Joined
Oct 3, 2005
Messages
1,569
Good morning

A toggle button has two states, up and down. Excel refers to them as TRUE or FALSE. Try this code attached to a toggle button:

Code:
Private Sub ToggleButton1_Click()
MsgBox ToggleButton1.Value
End Sub

HTH

DominicB
 

nadirv8

New Member
Joined
Sep 12, 2006
Messages
9
Thankyou, but how do I actually get:

"Togglebutton - False" to equal:
Code:
    Sheets("Holland").Select
    Range("D:D,H:H,L:L,P:P,T:T,X:X,AB:AB,AF:AF,AJ:AJ,AN:AN,AR:AR,AV:AV").Select
    Range("AV1").Activate
    Selection.EntireColumn.Hidden = True
    Sheets("Holland").Select
    Range("A1").Select

and "Togglebutton - True" to equal:
Code:
    Sheets("Holland").Select
    Range("D:D,H:H,L:L,P:P,T:T,X:X,AB:AB,AF:AF,AJ:AJ,AN:AN,AR:AR,AV:AV").Select
    Range("AV1").Activate
    Selection.EntireColumn.Hidden = False
    Sheets("Holland").Select
    Range("A1").Select

Thanks again
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi,

try
Code:
Selection.EntireColumn.Hidden = ToggleButton1.Value
kind regards,
Erik

EDIT: it togglebutton is on sheets "holland", then this will be enough: you don't need more codelines

Code:
    Range("D:D,H:H,L:L,P:P,T:T,X:X,AB:AB,AF:AF,AJ:AJ,AN:AN,AR:AR,AV:AV").EntireColumn.Hidden = ToggleButton1.Value
    Range("A1").Select
 

Forum statistics

Threads
1,141,152
Messages
5,704,594
Members
421,358
Latest member
Redstar13

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top