Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Check a Check Box with VB

What is the VB macro code to "check" a Check Box forms control ?



- Ronald K.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 420
Default Check a Check Box with VB

Try setting the value to True.



On 10/09/2011 06:14, kittronald wrote:
What is the VB macro code to "check" a Check Box forms control ?



- Ronald K.



--
Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Check a Check Box with VB

Dave,

Perhaps I'm not using the proper syntax.

Sheet2.CheckBox23.Value = True



- Ronald K.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Check a Check Box with VB

Dave,

Thanks for the quick response.

Apparently, pressing the Send button was the solution.

Sheet2.CheckBoxes("Check Box 23").Value = True

In the future, I'll press the Send button before posting a question. 8)




- Ronald K.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Check a Check Box with VB

Is this the shortest way to test if a Checkbox is already checked ?

Sub TEST()
If Sheet2.CheckBoxes("Check Box 23").Value = False Then
Sheet2.CheckBoxes("Check Box 23").Value = True
Else
Sheet2.CheckBoxes("Check Box 23").Value = True
End If
End Sub



- Ronald K.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Check a Check Box with VB

kittronald expressed precisely :
Is this the shortest way to test if a Checkbox is already checked ?

Sub TEST()
If Sheet2.CheckBoxes("Check Box 23").Value = False Then
Sheet2.CheckBoxes("Check Box 23").Value = True
Else
Sheet2.CheckBoxes("Check Box 23").Value = True
End If
End Sub



- Ronald K.


No need to make the If evaluation redundant, it just adds extra
processing for VBA. No big deal on one-by-one basis but the cummulative
effect can add up...

Sub TEST()
If Not Sheet2.CheckBox23 Then Sheet2.CheckBox23 = True
End Sub

...so if it's NOT True then it gets changed to True. No need to set it
to True if it's already True! No need to test if its value = False
because Value is its default property. IOW, the control can only be
True (checked) or False (unchecked).

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 420
Default Check a Check Box with VB

This looks like it's a checkbox from the Forms toolbar -- not from the control
toolbox toolbar.

You can use xloff or xlon.

And if you just want to make it checked, there's no reason to check first.

sheet2.checkboxes("check box 23").value = xlon

If you are processing something based on the checkbox, you could use:

if sheet2.checkboxes("check box 23").value = xlon then
'or = xloff to check to see if it's empty


On 10/09/2011 09:10, kittronald wrote:
Is this the shortest way to test if a Checkbox is already checked ?

Sub TEST()
If Sheet2.CheckBoxes("Check Box 23").Value = False Then
Sheet2.CheckBoxes("Check Box 23").Value = True
Else
Sheet2.CheckBoxes("Check Box 23").Value = True
End If
End Sub



- Ronald K.



--
Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Check a Check Box with VB

Garry,

Got it to work with a little modification.

If Not Sheet2.CheckBoxes("Check Box 23") Then
Sheet2.CheckBoxes("Check Box 23") = True

Thanks again.



- Ronald K.


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Check a Check Box with VB

Dave,

The Check Box is from the Forms toolbar.

If the Check Box was already checked, would repeatedly setting the Check
Box to xlon trigger events to execute again that are dependent on it being
checked ?



- Ronald K.


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Check a Check Box with VB

After serious thinking kittronald wrote :
Garry,

Got it to work with a little modification.

If Not Sheet2.CheckBoxes("Check Box 23") Then
Sheet2.CheckBoxes("Check Box 23") = True

Thanks again.



- Ronald K.


Ok, Ron. So as Dave suggests you are using Forms controls and not
ActiveX. My bad for not picking up on this. Glad you got it working...

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 420
Default Check a Check Box with VB

Sounds like you could add a msgbox to your code and test it pretty quickly.



On 10/11/2011 08:17, kittronald wrote:
Dave,

The Check Box is from the Forms toolbar.

If the Check Box was already checked, would repeatedly setting the Check
Box to xlon trigger events to execute again that are dependent on it being
checked ?



- Ronald K.



--
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
Copy and move check box (check boxes) with new cell link? Marty Excel Worksheet Functions 1 January 20th 10 07:43 PM
Loop through column(s) to check values, perform action based on check ward376 Excel Programming 4 November 6th 07 03:21 PM
Increase size of a Forms Check Box (click on to enter check mark) 718Satoshi Excel Discussion (Misc queries) 0 August 17th 07 01:52 AM
Check if Conditional Format is True or False / Check cell Color Kevin McCartney Excel Worksheet Functions 5 June 29th 07 11:12 AM
Enable check box in protected sheet + group check boxes Dexxterr Excel Discussion (Misc queries) 4 August 2nd 06 12:00 PM


All times are GMT +1. The time now is 04:01 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"