Excel hacks tips & tools for streamlining your spreadsheets o'reilly 2007

Page 114

HACK

Automatically Add Data to a Validation List

your formulas. The selected range address will show automatically in the InputBox, and all you need to do to make the conversion is click OK. H A C K

#38

Automatically Add Data to a Validation List

Hack #38

The validation feature in Excel is great, but there is one key thing it cannot do (without the following hack): automatically add a new entry to the list being used as the source for the validation list. This hack allows a user to add to the list, showing a message box and giving the user an option to Add or Cancel. Duplicates are ignored.

If you have used validation, you know it’s a neat feature. Perhaps most impressive is its ability to add a list to any cell from which the user can then select. Wouldn’t it be nice if, when you enter a new name in a validated cell, Excel automatically adds it to the list? This is possible, thanks to the following hack. Assume you have a list of names in the range A1:A10, as in Figure 2-24.

Figure 2-24. Workbook set up for validation list

These names represent employees in a company. It is not uncommon for new employees to be added to such a list, but at present, the only way to achieve this is to add the new names to the end of the list and then select the new names from the list in the validated cell. To overcome this limitation, follow these steps. In cell A11, enter the following formula and copy it down to row 20, as in Figure 2-25 (note the relative reference of A10): =IF(OR($D$1="",COUNTIF($A$1:A10,$D$1)),"x",$D$1)

Now, select Formulas ➝ Defined Names ➝ Define Name (pre-2007, Insert ➝ Name ➝ Define), and type MyNames in the Names: box. In the Refers To: box, enter the following formula, as shown in Figure 2-26, and then click OK (pre-2007, click Add then click OK): =OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A:$A),1)

Chapter 2, Hacking Excel’s Built-in Features |

91

#38


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.