ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Checkbox Help (https://www.excelbanter.com/excel-programming/324971-checkbox-help.html)

[email protected]

Checkbox Help
 
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???


Nate Oliver[_3_]

Checkbox Help
 
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

Jim Thomlinson[_3_]

Checkbox Help
 
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

" wrote:

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???



Chip Pearson

Checkbox Help
 
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



wrote in message
oups.com...
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???




[email protected]

Checkbox Help
 
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


Chip Pearson wrote:
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



wrote in message
oups.com...
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???



Dave Peterson[_5_]

Checkbox Help
 
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?)

wrote:

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

Chip Pearson wrote:
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



wrote in message
oups.com...
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???


--

Dave Peterson


All times are GMT +1. The time now is 08:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com