assign macro using vba

Dharris144

Board Regular
Joined
Jul 22, 2009
Messages
97
i have a sheet with a hundred check boxes. Can someone help with a VBA script to assign the same macro to all checkboxes on current sheet?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
My apologies for the slow response. This macro will loop through all the form control check boxes on the active sheet and assign their action to a macro titled "Test" in Module1.

Code:
Sub AssignCheckboxMacro()
Dim cb As Shape
  For Each cb In ActiveSheet.Shapes
    If cb.Type = msoFormControl Then
      If cb.FormControlType = xlCheckBox Then
        cb.OnAction = "[COLOR=#ff0000]Module1[/COLOR].[COLOR=#ff0000]Test[/COLOR]"
      End If
    End If
  Next cb
End Sub

You can change the name of the macro and the module name to match your target macro information.
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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