Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Check box making a command button work

Apologies - my code will run when the box is UNchecked! Change 'True'
to 'False' as needed...

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making Excel's open command work like Word 280Z28 Excel Discussion (Misc queries) 2 June 8th 06 04:56 PM
Worksheet Command Button will not work willpwr Excel Worksheet Functions 0 May 16th 06 08:13 PM
Assign Macro to Command Button doesn't work CLS Excel Programming 2 May 31st 05 05:42 PM
Embed command button from the control toolbox doesnt work guichre Excel Worksheet Functions 1 November 16th 04 02:28 AM
macro code doesnt work in command button The Grinch[_9_] Excel Programming 4 July 22nd 04 06:28 PM


All times are GMT +1. The time now is 02:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"