XL: How to Assign a Macro to an Option Button

ID: Q141689

The information in this article applies to:

SUMMARY

In Microsoft Excel, you can assign a macro to a custom option button so that when the option button is selected, the macro is run.

MORE INFORMATION

To create an option button, make sure the Forms toolbar is visible. In Microsoft Excel 97 or Microsoft Excel 98 Macintosh Edition, point to Toolbars on the View menu, and then click Forms. To display the Forms toolbar in Microsoft Excel versions 5.0 and 7.0, follow these steps:

1. On the View menu, click Toolbars.

2. In the Toolbar dialog box, click Forms.

3. Click OK.

To create an option button and assign a macro to it, follow these steps:

1. On the Forms toolbar, click Option Button and draw the outline of

   the button on the sheet.

2. Select any cell in the worksheet.

3. In Microsoft Excel 97, use the right mouse button to click the Option

   button and click Assign Macro on the shortcut menu. In Microsoft Excel
   5.0 or 7.0, use the right mouse button to click the option button (or
   press COMMAND and click it on a Macintosh computer), and then click
   Assign Macro on the Tools menu.

4. In the Assign Macro dialog box, click the name of the macro that
   you want to assign to the Option button, and then click OK.

When you click the Option button, the macro will be run.

REFERENCES

Microsoft Excel Version 7.0

For more information about assigning a macro to a control, click Answer Wizard on the Help menu and type:

  how do I assign a macro to a control

Microsoft Press: "Microsoft Excel/Visual Basic Programmer's Guide," version 7.0, Chapter 8, "Controls and Dialog Boxes"

Microsoft Excel Version 5.0

"Visual Basic User's Guide," version 5.0, Chapter 11, "Controls and Dialog Boxes"

For more information about Assigning a Macro to a Control in Microsoft Excel version 5.0, choose the Search button in Help and type:

   option buttons, creating

Additional query words: 5.00 5.00a 5.00c 7.00 8.00 XL97 assigning
Keywords          : kbprg
Version           : WINDOWS: 5.0,7.0,97; MACINTOSH: 5.0
Platform          : MACINTOSH WINDOWS
Issue type        : kbhowto

Last Reviewed: January 6, 1999