In all the spreadsheets I make on a weekly basis, at least 3 out of 4 contain a drop down box. It also happens to be one of the most asked questions I get as far as tricks people want to know about Excel. If you’ve never seen one before, the drop down box allows you to select values for a cell from a preset list… like below.

Now, I’m going to alter your paradigm view on the drop down box. From henceforth, be it known that this tool is really called data validation. Let me explain by showing the need for drop do.. er… data validation.
Say you want to create a spreadsheet that is shared among coworkers, and will be a log of their daily activities. You will calculate summaries each day based on the category of their activities. In order to make sure you don’t miss any activities in the cracks (due to misspelling, synonyms, etc) we need to provide a way for the user to validate their submission by the preset values you want. Hence the term data (something we’re gathering) validation (making sure it’s correct).
You can actually validate data in many ways; the method most used is the List option (aka drop down). You can either enter the allowed values manually, or enter the values in your spreadsheet and reference them in the data validation tool (the best method).
To set up validation, select the cell(s) you want to become validated. Go to Data -> Data Validation. The following popup will appear. Under Allow, select List. Make sure the two checkboxes are selected. Now, under Source, simply enter the range that contains your values. If you want to enter the values manually, simply enter them in (without an ‘=’ sign) and separated by commas (again, not recommended).

Other sheets?
Excel does not allow you to reference cells as a source that are contained on another sheet. However (of course) there is a workaround. Simply create a named range for the cells you need and then in the source enter =NamedRange.
Dynamic ranges
Sometimes you may have a range of values that could grow (i.e. you or the user can add more values later on). You can set the range to be x number of cells more than you need, but then it will show up as extra options in the drop down. So, a workaround I use all the time is to use the OFFSET() formula to automatically generate the range. It looks like this..
The OFFSET() formula uses this syntax:
=OFFSET(reference, rows, cols, [height], [width])
Our function for the validation will use this syntax:
=OFFSET(CellWithFirstValue,0,0,COUNTA(ColumnOfValues)-1,1)
CellWithFirstValue (reference)
The first possible cell that contains a value to use in your validation. It is assuming all other values will come directly after this one with no gaps.
0,0 (rows, cols)
This is saying go 0 rows across and 0 columns down to get to the first value.
COUNTA(ColumnOfValues)-1 ([height])This will return the “height” of our range. It’s a simple count or counta of all potential values in that column. Subtract one if you have a header row, or any values that are in cells above the reference one (above).
1 ([width])
This makes our “range” 1 column wide.
If you want values on another page, put this formula into a named range and then use in the source. Otherwise, you can entire the entire formula into the source box.
Next week (part 2), I’ll show you how to use the advanced features of data validation (i.e. input and error messages, bulk modifications) and how to make the values in the data validation change automatically based on a value in another drop down box.
Download this spreadsheet to review the content in this lesson.
Enjoy!

Read on your mobile device
Posted in Excel, Formula Friday
|
3 Comments