Checkbox Help

  • Thread starter Thread starter pkruti
  • Start date Start date
P

pkruti

Is there a way in code to check a checkbox on an excel spreadsheet when
a command button is clicked? i tried the following but it didnt seem to
work: it gave an error saying "Object required"??

Sub SendAll_Click ()

If CheckBox1.Value = 0 then
CheckBox1.Value = 1
End if

End Sub

Any ideas on what i am may be doing wrong???
 
Hello,

I'm not sure why you're using a conditional, but try the following:

Private Sub CommandButton1_Click()
Me.CheckBox1 = True
'' toggle:
'Me.CheckBox1 = Not Me.CheckBox1
End Sub


Regards,
Nate Oliver
 
I am assuming that you got your checkbox from the control toolbox and not the
forms toolbar. You need to reference the sheet

Private Sub CommandButton1_Click()
Sheet1.CheckBox1.Value = True
End Sub

for example... HTH
 
If your checkboxes are from the Controls toolbar, use

Private Sub CommandButton1_Click()
If Sheet1.CheckBox1.Value Then
Debug.Print "checked"
Else
Debug.Print "unchecked"
End If
End Sub

If the checkboxes are from the Forms toolbar, use

If Worksheets("Sheet1").CheckBoxes("Check Box 3").Value = 1 Then
Debug.Print "checked"
Else
Debug.Print "unchecked"
End If



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
I have tried all of the above and still not working. I am using the
checkboxes from the the Forms toolbar.

and what i want is once i click on a command button i want it to check
if the checkbox has been checked if not then i want to check it but i
want to do all of this with code and not have to maunally check the
box. is this possible in VBA or no becuase i tried the following code:
and it doesnt check the box??? what am i doing wrong???

If Worksheets("Brick").CheckBoxes("Check Box 1").Value = 1 Then
Debug.Print "checked"
Else
Debug.Print "unchecked"
End If
 
I put a buttons from the Forms toolbar on the worksheet with the checkboxes from
the Forms toolbar.

I assigned this macro to that button.

Option Explicit
Sub testme()

Dim CBX As CheckBox
For Each CBX In ActiveSheet.CheckBoxes
CBX.Value = xlOn
Next CBX

End Sub


(Why bother checking to see what the value is if you're going to make it xlOn
anyway?)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top