Assign Macro to Checkbox

  • Thread starter Thread starter jafsonic
  • Start date Start date
J

jafsonic

I have a series of checkboxes which affect conditional formatting in
other cells in each given row where the checkbox is located. The code
is generic enough to use with every checkbox. I could call a
subroutine from each checkboxY.click command, but is there a way to set
all the checkboxes to just use the one routine?

Thanks, this is driving me nuts and I don't want to have to edit EVERY
single macro.
 
If you used a checkbox from the Forms toolbar, you could assign the same macro
to each checkbox.

Option Explicit
Sub testme()

Dim CBX As CheckBox
Set CBX = ActiveSheet.CheckBoxes(Application.Caller)

If CBX.Value = xlOn Then
MsgBox "it's checked"
Else
MsgBox "Nope"
End If

MsgBox CBX.Name & vbLf & CBX.TopLeftCell.Address(0, 0)

End Sub


Rightclick on the checkbox and choose assign macro. This macro would go into a
General module--not behind the worksheet like the code for checkboxes for the
control toolbox toolbar version.
 
Use checkboxes from the Forms toolbar, and assign them all to the same
macro, use

Application.Caller

to check which has been clicked.

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 
Thank You,

If I use a forms checkbox, will I still be able to reference the
current / selected row that the checkbox is in?
 
Checkboxes, from the Forms toolbar or the Controls toolbox, do not reside on
a row, they are on a layer extra the worksheet. You could link it tom a
cell, but better to just check the name IMO

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 
IMO?


Bob said:
Checkboxes, from the Forms toolbar or the Controls toolbox, do not reside on
a row, they are on a layer extra the worksheet. You could link it tom a
cell, but better to just check the name IMO

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 
Thanks, Dave... and btw, your code worked like a charm when adapted to
my application.

Thanks... again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top