How Do I Get the Value of a CheckBox that Made Macro Call

MikeMcCollister

Board Regular
Joined
May 6, 2020
Messages
55
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet that has a checkbox on it. Because this spreadsheet will be edited many times, the checkbox will ultimately have multiple copies. Each checkbox will be calling the same macro. I want it this way because I don't want to create a new macro whenever I edit the spreadsheet. The ultimate plan is to have all checkboxes change to state of the checkbox that was just checked. So, is there a way to detect the state of the checkbox that triggered the macro?

Thanks,

Mike
 

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,203
Office Version
  1. 365
Platform
  1. Windows
Not sure what the point of multiple checkboxes is, if they all have the same value, but are they Form control checkboxes?
 

MikeMcCollister

Board Regular
Joined
May 6, 2020
Messages
55
Office Version
  1. 365
Platform
  1. Windows
One question, if I use an ActiveX control checkbox, how do I attach a macro to that?

Thanks,

Mike
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,711
Office Version
  1. 2010
Platform
  1. Windows

ADVERTISEMENT

You don't attach a macro to ActiveX controls... you put your code in its event procedures (similar to the way controls work on UserForms).
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,203
Office Version
  1. 365
Platform
  1. Windows
You can find the value of the checkbox that was clicked like
VBA Code:
   Dim x As Long
   x = ActiveSheet.Shapes(Application.Caller).ControlFormat.Value
1 is checked & -4146 is unchecked
 

MikeMcCollister

Board Regular
Joined
May 6, 2020
Messages
55
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Fluff and Rick,

Thank you both for your help.

I like that the ActiveX version puts the code in the sheet that I am using. Also, I can change the text color too, which I like. However, it does not look as crisp on the screen as the form control checkbox.

Just looking at the various options that I have.

Mike
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,203
Office Version
  1. 365
Platform
  1. Windows
I tend to avoid ActiveX controls wherever possible as they are notoriously flaky.
 

MikeMcCollister

Board Regular
Joined
May 6, 2020
Messages
55
Office Version
  1. 365
Platform
  1. Windows
Fluff,

I'm starting to see how flaky the ActiveX control is.

Now if I can just change the color of the text in the form control checkbox to white. My life would be good.

Regards,

Mike
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,203
Office Version
  1. 365
Platform
  1. Windows
AFAIK, you cannot change the text colour, are you trying to hide the text, or make it visible against a dark background?
 

Watch MrExcel Video

Forum statistics

Threads
1,123,158
Messages
5,600,054
Members
414,357
Latest member
Gemma_R

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
Top