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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,008
Members
448,935
Latest member
ijat

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
Back
Top