If-Clause in VBA to look at checkbox if its checked or not

zorc

New Member
Joined
Apr 15, 2003
Messages
6
Hello!

let's say i have "check box 20" and i want to make an IF-clause to check, if this same box is checked or unchecked.

This makes it enabled i have figured out myself yay! ;)

ActiveSheet.Shapes("Check Box 20").Select
With Selection
.Value = xlOn

So Is it possible to make IF-clause to "sniff" that box if its checked or not?

Thanks a million!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
You are almost there really:

Code:
If ActiveSheet.Shapes("Check Box 20").Value = xlOn Then
  MsgBox "Checked
Else
  MsgBox "Unchecked
End If
 
Upvote 0
:(

Tried that and i get this error message:

Run-time error '438':

Object does not support this property or method.

on debug, following line is highligted:
If ActiveSheet.Shapes("Check Box 20").Value = xlOn Then
 
Upvote 0
Good morning...

MsgBox IIf(CheckBox1.Value, "CHECKED", "UNCHECKED")

the xlOn constant works, but this is not the correct constant to use. Any non zero value will evaluate to TRUE. xlOn = 1

Use TRUE or FALSE. If the "TripleState" property is set to true, the above will not do. You would need to test for a third value as well. This being 'Null'.

Tom

Yeah. The Control Toolbox. I missed that. :)
 
Upvote 0
DUDE! Your troubles will all melt away if you use the Control Toolbox instead. Give it a whirl and you will see what I mean. The controls there are MUCH more robust.
 
Upvote 0
sigh

none of those are working or im just totally handless :P Changed to the control toolbox checkbox but all i get is errors :(

So if anyone will give me tested if-clause that works, ill be happy for rest of this year! thanks :)
 
Upvote 0
Put this code on the new CheckBox:

Code:
Private Sub CommandButton1_Change()
   If CommandButton1.Value = False Then
      MsgBox "You unchecked the box"
   Else
      MsgBox "You checked the box"
   End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,563
Messages
6,114,332
Members
448,566
Latest member
Nickdozaj

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