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 :)
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

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
 

Watch MrExcel Video

Forum statistics

Threads
1,108,910
Messages
5,525,583
Members
409,651
Latest member
Quasar Hunter

This Week's Hot Topics

Top