Hack 23 Support Multiple Lists in a ComboBox

   

figs/moderate.gif figs/hack23.gif

When working with multiple lists, you can force a list to change by using a combination of option buttons plus a ComboBox .

Excel offers many ways for users to select items from a list, be they names , products, days of the weekwhatever the list is composed of. However, to access more than one list of choices simultaneously generally requires that you use three separate controls, such as three ComboBox controls from the Forms toolbar.

Instead, you can use a ComboBox in combination with option buttons (also called radio buttons and also found on the Forms toolbar) to have a list change automatically according to which option button you choose. To see how this works, enter the numbers 1 through 7 in the range A1:A7 on a new worksheet. In B1:B7, enter the days of the week starting with Monday and ending with Sunday . In C1:C7, enter the months January through July .

Excel's auto-fill features can make this task much easier. Enter 1 in cell A1, select cell A1, press the Ctrl key, and then left-click the fill handle. While holding down the left mouse button and the Ctrl key simultaneously, drag down to row 7. Excel will fill in the numbers for you. Next, enter Monday in cell B1 and double-click the fill handle for this cell. Enter January in cell C1 and double-click the fill handle for this cell. Excel will fill in the days and months for you!


Select View Toolbars Forms and double-click the option button on the toolbar. Then, click the spreadsheet anywhere in three separate spots to place three option buttons on the spreadsheet.

Now, click the ComboBox and again click somewhere on the spreadsheet to insert a ComboBox on it. Using the drag handles, size the ComboBox to a manageable size and position the option buttons so that they're directly below the ComboBox.

Left-click the first option button, select Edit Text, then replace the words Option Button 1 with the word Numbers . Use the same process for Option Button 2, replacing with the word Weekdays , and for Option Button 3, replacing with the word Months . This is shown in Figure 2-8.

While holding down the Ctrl key, click each option button so that all three are highlighted, then right-click and select Format Control Control. Specify cell $F$1 as the cell link (make sure it is absoluteuse those dollar signs).

In cell E6, enter the following formula:

 =ADDRESS(1,$F)&":"&":"ADDRESS(7,$F) 

Select Insert Name Define. In Names in Workbook:, type MyRange , and in the Refers To: field, type the following:

 =INDIRECT($E) 

Click Add, and then click OK. Right-click the ComboBox and select Format Control Control. Make the Input range MyRange and the cell link $G$1 , then click OK. You should be able to select one of the option buttons, and the list within the ComboBox should automatically reflect which option button you chose.

Figure 2-8. A multilist ComboBox controlled by option buttons
figs/exhk_0208.gif

When setting this up for your own spreadsheet, you should use some offscreen cells for the ComboBox links and lists. You might even want to hide these cells from users so that your links stay where they should. Also, you need to modify the two ADDRESS functions to reflect the cell range you are using. In the ADDRESS functions we used in this example, 1 represents the first row number of the lists, while 7 represents the last row number.



Excel Hacks
Excel Hacks: Tips & Tools for Streamlining Your Spreadsheets
ISBN: 0596528345
EAN: 2147483647
Year: 2003
Pages: 136

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net