Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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???

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default 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???


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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???



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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???




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default 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
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
checkbox Sandee Excel Discussion (Misc queries) 1 April 17th 08 04:43 PM
How to have Checkbox A uncheck with checked Checkbox B Texas Aggie Excel Discussion (Misc queries) 3 July 20th 07 10:58 PM
Checkbox!! Oppy Excel Discussion (Misc queries) 2 October 14th 05 05:28 PM
Checkbox Luke Excel Discussion (Misc queries) 1 October 14th 05 01:58 PM
checkbox Paul P Excel Programming 0 September 10th 03 08:56 PM


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

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

About Us

"It's about Microsoft Excel"