XL97: Grouping ActiveX Option Buttons on a Worksheet

ID: Q159489

The information in this article applies to:

SUMMARY

In the Visual Basic Editor, when you add option buttons from the Control Toolbox to a worksheet, the option buttons form one group by default. All of the option buttons are mutually exclusive; when you click one option button in a group, all other option buttons in the same group are set to False.

This article discusses how you can create multiple groups of option buttons on a worksheet.

MORE INFORMATION

You can set the GroupName property for an option button to determine the group for which the control is a member. All option buttons with the same GroupName within a single worksheet are mutually exclusive. You can use the same group name in two worksheets; however, doing so creates two groups (one in each worksheet) rather than one group that includes the option buttons in both worksheets.

NOTE: On a UserForm in a Visual Basic for Applications project, you can use a frame control to group option buttons. The ActiveX frame control is not available on the Control Toolbox for worksheets.

The following example demonstrates how to create two groups of option buttons on a worksheet by setting the GroupName property for the controls.

Drawing the Option Button Controls on a Worksheet

1. Open a new workbook.

2. Point to Toolbars on the View menu and click Control Toolbox to display

   the Control Toolbox toolbar.

3. Click Option Button on the Control Toolbox, and then draw the control on
   the worksheet. Repeat this step three times until there are four option
   button controls on the worksheet.

4. Click Exit Design Mode on the toolbar.

5. Test the option buttons by clicking each one.

Notice that only one option button on the worksheet can be set to True at a time. (The four option buttons you added to the worksheet make up a single group.)

Separating the Option Buttons into Multiple Groups

Using the option buttons you created in step 3 in the previous section, do the following:

1. Click Design Mode on the Control Toolbox toolbar.

2. Click OptionButton1, and then press SHIFT and click OptionButton2 to

   select both buttons.

3. Click Properties on the Control Toolbox toolbar.

4. In the Properties window, type "Group1" (without the quotation marks)

   for the GroupName property.

5. Click OptionButton3, and then press SHIFT and click OptionButton4 to
   select both buttons.

6. If the Properties window is not visible, click Properties on the Control
   Toolbox toolbar.

7. In the Properties window, type "Group2" (without the quotation marks)
   for the GroupName property.

8. Click Exit Design Mode on the Control Toolbox toolbar and close the
   Properties window.

9. Click each option button on the worksheet. Notice that only one button
   in Group1 can be set to True, and only one button in Group2 can be set
   to True.

REFERENCES

For more information about ActiveX controls, click the Index tab in Microsoft Visual Basic Help, type the following text

   ActiveX

and then double-click the selected text to go to the "Understanding Automation" topic.

Additional query words: XL97 8.0 8.00 options

Keywords          : kbualink97 xlui xldraw 
Version           : WINDOWS:97
Platform          : WINDOWS
Issue type        : kbhowto

Last Reviewed: November 1, 1998