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:

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
you can simply set the value property of the checkbox to TRUE/FALSE

Code:
 Me.CheckBox1.Value = True

thanks. Can you be more specific - what does the "Me" mean?


In that case you can just link it to a cell and use the cell value (1 or 0) to check or uncheck the box.

I tried this and while the "0" unchecked them correctly, entering the "1" put the check back in but the value did not return. I think the first way would work best, just need to understand what the complete VBA code is.

Thakns!
 
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
 
Upvote 0
Thanks, Tiger.

I opted for the checkbox17.value=False route, but I am still having difficulties.

Here's my code...

Sub xx ()

Sheets("worksheet1").Select
Checkbox17.Value = False

End sub

Am I missing something?
 
Upvote 0
Hey Gumercindo - can you tell us exactly what you would like to do and maybe we can work on the complete code? This code works for me.

Code:
Private Sub CheckBox1_Click()

Sheet1.CheckBox1.Value = False

End Sub
 
Last edited:
Upvote 0
If it's a Forms checkbox, you can use:
Code:
Sheets("worksheet1").Checkboxes("Checkbox17").Value = False
using the relevant name.
 
Upvote 0

Forum statistics

Threads
1,223,714
Messages
6,174,044
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