Checking the value of a checkbox with VBA???

mlopes1

Board Regular
Joined
Jul 14, 2002
Messages
114
I have a checkbox with text showing "Formulas".

How do I see if its been checked? All the examples I find use code such as

if checkbox1.value = -1 then

But where do I see what the name of my checkbox is? In their examples its checkbox1, but where do you get this from? I don't see anywhere to name it. I know this is simple but its driving me nuts. Thanks,

mark
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
On 2002-08-29 09:22, mlopes1 wrote:
I have a checkbox with text showing "Formulas".

How do I see if its been checked? All the examples I find use code such as

if checkbox1.value = -1 then

But where do I see what the name of my checkbox is? In their examples its checkbox1, but where do you get this from? I don't see anywhere to name it. I know this is simple but its driving me nuts. Thanks,

mark

Hi,

on the checkbox right-click and select properties.
The top properties is (Name) This is what the Checkbox1 is refering to.

BUT, this ONLY applies to the Checkboxes from the Controls toolbar (if you are using them on a sheet and not a Userform), you can't get properties for the Forms Buttons/Checkboxes etc.

Hope this helps
 
Upvote 0
Ian,

Thank you, that was what I needed to know. Very simple but much appreciated!

Mark
This message was edited by mlopes1 on 2002-08-29 09:41
 
Upvote 0
I think I understand you. What you want is for the commandbutton to do something when the checkbox is checked, or not checked. See my example below. I think this is what you want.


Private Sub CommandButton1_Click()
' If checkbox is selected, it runs TRUE.
' If checkbox is not selected, it runs FALSE
' Swap out the msgbox for your code

If CheckBox1 = True Then
MsgBox "TRUE" 'Insert whatever code on this line
Else
MsgBox "FALSE 'Likewise here
End If

End Sub

Hope this helps.
 
Upvote 0
Thanks for the help. I have another question. In checking the value of the checkboxes, I keep getting "object required". here is the code I used:

If PF1.Value = -1 Then
where PF1 is the name I assigned the check box. I also have tried

If PF1 = true
If PF1.checked


Any help???

Mark
This message was edited by mlopes1 on 2002-08-29 10:39
 
Upvote 0
On 2002-08-29 10:06, mlopes1 wrote:
Thanks for the help. I have another question. In checking the value of the checkboxes, I keep getting "object required". here is the code I used:

If PF1.Value = -1 Then
where PF1 is the name I assigned the check box. I also have tried

If PF1 = true
If PF1.checked


Any help???

Mark
This message was edited by mlopes1 on 2002-08-29 10:39

can you post the full code your using.

the fullowing work fine for me:

Private Sub CheckBox1_Click()

If Me.CheckBox1 = -1 Then
[a1] = -1
Else
[a1] = 0
End If

End Sub

Also, are you using them on a Worksheet or on a Userform?
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top