Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Check box making a command button work
Hello I have a check box on a sheet from the forms toolbar I would like to make a command button work only when the check box is ticked Thank you -- Rmagic ------------------------------------------------------------------------ Rmagic's Profile: http://www.excelforum.com/member.php...o&userid=28595 View this thread: http://www.excelforum.com/showthread...hreadid=484465 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Check box making a command button work
Insert the following at the beginning of your CommandButton1_click
code: If CheckBox1.Value = True Then Exit Sub End If This way, the sub will end before anything gets done. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Check box making a command button work
Apologies - my code will run when the box is UNchecked! Change 'True'
to 'False' as needed... |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Check box making a command button work
I used a button from the forms toolbar--is that what you meant?
You could either add some code to the button's code: Option Explicit Sub btnClick() If ActiveSheet.CheckBoxes("Check box 1").Value = xlOff Then MsgBox "nope, not today!" Exit Sub End If 'your real code here MsgBox "it's working" End Sub Or you could disable the button (or hide it) when the checkbox changes: Option Explicit Sub CBXClick() ActiveSheet.Buttons("button 1").Enabled _ = CBool(ActiveSheet.CheckBoxes("Check box 1").Value = xlOn) 'or hide it??? ActiveSheet.Buttons("button 1").Visible _ = CBool(ActiveSheet.CheckBoxes("Check box 1").Value = xlOn) End Sub If you really meant a commandbutton from the control toolbox toolbar, something like: Sub CBXClick() ActiveSheet.CommandButton1.Enabled _ = CBool(ActiveSheet.CheckBoxes("Check box 1").Value = xlOn) 'or to hide it ActiveSheet.CommandButton1.Visible _ = CBool(ActiveSheet.CheckBoxes("Check box 1").Value = xlOn) End Sub But the same kind of check inside the commandbutton's code would work ok (like in btnclick procedure). Rmagic wrote: Hello I have a check box on a sheet from the forms toolbar I would like to make a command button work only when the check box is ticked Thank you -- Rmagic ------------------------------------------------------------------------ Rmagic's Profile: http://www.excelforum.com/member.php...o&userid=28595 View this thread: http://www.excelforum.com/showthread...hreadid=484465 -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Making Excel's open command work like Word | Excel Discussion (Misc queries) | |||
Worksheet Command Button will not work | Excel Worksheet Functions | |||
Assign Macro to Command Button doesn't work | Excel Programming | |||
Embed command button from the control toolbox doesnt work | Excel Worksheet Functions | |||
macro code doesnt work in command button | Excel Programming |