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

##### New Member
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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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

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

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``````

sorted! thankyou

Dave

Replies
4
Views
236
Replies
4
Views
871
Replies
2
Views
671
Replies
1
Views
594
Replies
1
Views
3K

1,217,680
Messages
6,137,948
Members
450,100
Latest member
mscetr

### 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.

### Which adblocker are you using?

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

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