VBA Form Control to Check & Uncheck some Checkboxes

Elisa2021

New Member
Joined
Dec 14, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I apologize if this is a duplicate post - I have been searching the internet for VBA code so when I click one checkbox, it selects 25 out of 39 total checkboxes on the tab, and then deselects all checkboxes when unchecked. I am using Form Controls and working with Excel 365. I have come across a few options, but I can't get them to work. I think I'm missing something in the code. Here is the "best" I've found so far, but I get a run-time error 424. It says Object required and then it highlights the first row.

1639492815457.png


What am I missing? :oops:
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi & welcome to MrExcel.

Your code refers to ActiveX controls. Since you're using Form controls it will not work. Try something like below.
Note that each macro needs to be assigned to the appropriate Form control. Put each macro in the worksheet's code module.
VBA Code:
Public Sub OnCheckBox104()
   
    Me.Shapes("Check Box 93").DrawingObject.Value = Me.Shapes("Check Box 104").DrawingObject.Value
    Me.Shapes("Check Box 98").DrawingObject.Value = Me.Shapes("Check Box 104").DrawingObject.Value

End Sub
 
Upvote 0
Solution
I apologize - I don't quite understand what you mean by each macro needs to be assigned to the appropriate Form Control or how to put each macro in the worksheet's code module. This is probably basic information, but I've never had formal VBA training. I am good at modifying existing code, but I have no clue how to go about doing these steps. :oops:

You have, however, fixed my problem! I'm updating my checkboxes to be ActiveX and using the original code I posted above. This seems to work!

I prefer to work with ActiveX controls, and was only using Form controls because I didn't build the original worksheet. However, since I'm in charge of it now, I'm going to do it my way! I think this will be a better solution long-term for my problem.

Thank you SO MUCH for pointing out what I was doing wrong (trying to use ActiveX code for Form Controls)!!!!
 
Upvote 0
I would recommend that you stick with Form Controls, as ActiveX ones are known to be a bit flaky & can cause problems.
 
Upvote 0
You are welcome and thanks for letting me know. For the mentioned reasons I second @Fluff's suggestion.
 
Upvote 0
Just as a follow up to my original post, I have gone though my document and updated all of the Form Control checkboxes to be ActiveX checkboxes. I have actually only worked with ActiveX in the past. I prefer these, at least for what I need the checkboxes to do. Here is my code:

1639510918911.png


When I check my "Pass button" aka CheckBox1, the VBA code checks all of the listed checkboxes. When I uncheck it, it unchecks all of the listed check boxes. As far as what my check boxes do, when say, CheckBox8 in the above is checked, it collapses every row in that section except for rows with some value (an x or a 1 or some character, doesn't matter what character) entered into the column q range. Here's the code for hiding/unhiding rows (this code works just fine, but I'm providing it in case it helps someone else.):
1639511199651.png

I really appreciate the help provided today! Thanks again! My problem is SOLVED. ?
 
Upvote 0

Forum statistics

Threads
1,214,980
Messages
6,122,563
Members
449,088
Latest member
Motoracer88

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