Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Determine check status of worksheet checkbox?

I have a checkbox on a worksheet but can't figure out how to tell in
VBA whether it's checked or not.

I reference the check box with:

Sheets("Mysheet").Shapes("MyCheckBox")

Can someone tell me the syntax to determine the check status?

Thanks.

John

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Determine check status of worksheet checkbox?

Checkbox from the Forms toolbar:

if worksheets("mySheet").checkboxes("myCheckbox").val ue = xlon then
'it's checked

Checkbox from the Control toolbox toolbar:

If Worksheets("mysheet").mycheckbox.Value = True Then
'it's checked

robotman wrote:

I have a checkbox on a worksheet but can't figure out how to tell in
VBA whether it's checked or not.

I reference the check box with:

Sheets("Mysheet").Shapes("MyCheckBox")

Can someone tell me the syntax to determine the check status?

Thanks.

John


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Determine check status of worksheet checkbox?

VBA whether it's checked or not.

I reference the check box with:

Sheets("Mysheet").Shapes("MyCheckBox")

Can someone tell me the syntax to determine the check status?


I'm newly returned to Excel, so I'm not up-to-date on everything about it,
so I'm not sure of you Shapes reference; but when I put a CheckBox on a work
sheet, I do it from the Visual Basic ToolBox and draw it directly onto the
sheet. I can then reference it directly within VBA using its name... and the
property you want is the Value property. Use

MyCheckBox.Value

for code on the Worksheet itself. If you are referencing across Worksheets,
then use

Sheets("Mysheet").MyCheckBox.Value

The Value property will be either True (if checked) or False (if not
checked).

Rick

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Determine check status of worksheet checkbox?

Thanks! xlOn works....but who at Microsoft developed that?!! Now I
don't feel so bad for not figuring that out. And xlOff = -4146?

My macro will be cross-platform and objects from the VB Toolbox don't
function correctly on a Mac (at least not drop down boxes). I'm not
sure why, but I'm forced to use the Forms toolbox on the worksheet.

** Is there any way to capture events with the Forms checkbox (like
when the checkbox is checked/unchecked)? **

Thanks!

John

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Determine check status of worksheet checkbox?

I meant objects from the *Control* tool box don't work on the Mac.

Rick, I'm also not able to create a check box from the VB Toolbox.
When I click off a form in VB, the toolbox disappears.

Thanks.

John




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Determine check status of worksheet checkbox?

You could assign it a macro (rightclick on it an assign macro).

Option Explicit
Sub testme()

Dim myCBX As CheckBox
Set myCBX = ActiveSheet.CheckBoxes(Application.Caller)

If myCBX.Value = xlOn Then
MsgBox "It's checked"
Else
MsgBox "It's not checked"
End If

End Sub

This goes in a general module.

By using this line:
Set myCBX = ActiveSheet.CheckBoxes(Application.Caller)
You can assign the same macro to all the checkboxes -- and still know which one
was clicked (Application.caller will return its name).

robotman wrote:

Thanks! xlOn works....but who at Microsoft developed that?!! Now I
don't feel so bad for not figuring that out. And xlOff = -4146?

My macro will be cross-platform and objects from the VB Toolbox don't
function correctly on a Mac (at least not drop down boxes). I'm not
sure why, but I'm forced to use the Forms toolbox on the worksheet.

** Is there any way to capture events with the Forms checkbox (like
when the checkbox is checked/unchecked)? **

Thanks!

John


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Determine check status of worksheet checkbox?

Thanks! xlOn works....but who at Microsoft developed that?!! Now I
don't feel so bad for not figuring that out. And xlOff = -4146?

My macro will be cross-platform and objects from the VB Toolbox don't
function correctly on a Mac (at least not drop down boxes). I'm not
sure why, but I'm forced to use the Forms toolbox on the worksheet.

** Is there a way to disable (gray out) checkboxes created from the
Forms toolbox? **


so I'm not sure of you Shapes reference; but when I put a CheckBox on a work
sheet, I do it from the Visual Basic ToolBox and draw it directly onto the


When I click off a VB form, the VB ToolBox goes away. Are you talking
about another toolbox like the Controls or Forms from the worksheet
level or am I missing something?

Thanks!

John

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Determine check status of worksheet checkbox?

You can disable those checkboxes with something like:

ActiveSheet.CheckBoxes("check box 1").Enabled = False

But they won't grey out. You may want to hide them???

ActiveSheet.CheckBoxes("check box 1").Visible = False

robotman wrote:

Thanks! xlOn works....but who at Microsoft developed that?!! Now I
don't feel so bad for not figuring that out. And xlOff = -4146?

My macro will be cross-platform and objects from the VB Toolbox don't
function correctly on a Mac (at least not drop down boxes). I'm not
sure why, but I'm forced to use the Forms toolbox on the worksheet.

** Is there a way to disable (gray out) checkboxes created from the
Forms toolbox? **

so I'm not sure of you Shapes reference; but when I put a CheckBox on a work
sheet, I do it from the Visual Basic ToolBox and draw it directly onto the


When I click off a VB form, the VB ToolBox goes away. Are you talking
about another toolbox like the Controls or Forms from the worksheet
level or am I missing something?

Thanks!

John


--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Determine check status of worksheet checkbox?

(last post was something old... google burped!)

Dave... thanks for the macro suggestion. I like the generic
"Application.Caller".

John


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Determine check status of worksheet checkbox?

I meant objects from the *Control* tool box don't work on the Mac.

Rick, I'm also not able to create a check box from the VB Toolbox.
When I click off a form in VB, the toolbox disappears.

Thanks.

John


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
all the check boxes should be checked if i check a particular checkbox in that row [email protected] Excel Programming 3 April 18th 07 09:20 AM
Determine when checkbox is clicked wAyne Excel Discussion (Misc queries) 1 February 21st 06 08:35 PM
Checking the status of a checkbox in a user form Peter Rooney Excel Programming 15 November 1st 05 03:59 PM
Syntax to check protected status of a worksheet? [email protected] Excel Discussion (Misc queries) 2 January 18th 05 02:53 PM
Can't check ActiveX checkbox on worksheet onedaywhen Excel Programming 3 August 9th 03 02:34 AM


All times are GMT +1. The time now is 04:13 PM.

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

About Us

"It's about Microsoft Excel"