Command for checking a checkbox in VBA?

gumercindo

New Member
Joined
Jun 14, 2006
Messages
24
Hi, simple question that I couldn't seem to find the answer for using the search command. I have a worksheet with a series of checkboxes. I'd like to run a macro that would check SOME of them and then uncheck them.

I tried recording the macro first, but the recording did not recognize me checking the checkbox. I also tried writing a VBA script that would add a space (" ") to that checkbox and that seemed to work but not optimal for adding the check makrs back in.

Any ideas?

Thanks!

btw, it's a form checkbox.
 
Last edited:
Hey tiger:

I have a worksheet with a series of checkboxes. Once a checkbox is "checked", the values will appear in the adjoining cell. If it's unchecked, no values (the worksheet performs some sort of lookup to another main sheet with all the data). Does this make sense to you?

So, I'm trying to create a macro that would uncheck certain boxes based on a certain scenario.
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
okay - so I would suggest that RORYA'S solutions would work best with maybe an If...Else...statment.

So, for example,

Code:
If some condition = this then 
Sheets("worksheet1").Checkboxes("Checkbox17").Value = False
else
Sheets("worksheet1").Checkboxes("Checkbox17").Value = True
End if
 
Upvote 0
Or even:
Code:
Sheets("worksheet1").Checkboxes("Checkbox17").Value = (somecondition = this)
 
Upvote 0
If it's a Forms checkbox, you can use:
Code:
Sheets("worksheet1").Checkboxes("Checkbox17").Value = False
using the relevant name.

Thanks.

I tried this in this format:

Code:
Sub mymacro()

Sheets("My worksheet name here").CheckBoxes("Checkbox17").Value = False


End Sub

And the error message I recieve says "Run-time error 1004", Unable to get the CheckBoxes property of the Worksheet class.
 
Upvote 0
I'd check the name of the check box - by default it would be:
Code:
Checkboxes("Check Box 17")
rather than:
Code:
Checkboxes("Checkbox17")
if it's a Forms checkbox.
 
Upvote 0
Hi - This is from the help file - it will explain Me far better than I can. You don't have to use Me though, you can just refer to the respective checkbox by its index number, i.e. checkbox1.value = this or checkbox2.value = that. You can also asign a variable(i) to the index number of the checkbox to cycle through all of your checkboxes.



The Me keyword behaves like an implicitly declared variable. It is automatically available to every procedure in a class module. When a class can have more than one instance, Me provides a way to refer to the specific instance of the class where the code is executing. Using Me is particularly useful for passing information about the currently executing instance of a class to a procedure in another module. For example, suppose you have the following procedure in a module:

Sub ChangeFormColor(FormName As Form)
FormName.BackColor = RGB(Rnd * 256, Rnd * 256, Rnd * 256)
End Sub

You can call this procedure and pass the current instance of the Form class as an argument using the following statement:

ChangeFormColor Me
Can you explain how to use the me.control? When I run the code, I get a compilation error reading:

Method or data member not found​

 
Upvote 0

Forum statistics

Threads
1,223,714
Messages
6,174,051
Members
452,542
Latest member
Bricklin

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