Combine data validation and conditional formatting to implement an easy-to-use dynamic banding option for your users.
Thanks to conditional formatting, you can apply several banding schemes to your Excel worksheets, and we've discussed several of them already. One possibility we haven't reviewed, however, is using data to determine which rows are banded. Throw in a little data validation and you can let users band (or shade) specific rows by simply choosing an item from a list.
To illustrate this technique, we'll use data validation to display category values. When the user chooses a category, conditional formatting will shade records for the selected category. For example, I choose Beverages from the data validation list is G2 to identify all beverage records.
Implementing this banding scheme is easier than you might think. First, we'll create a unique list of category values from the actual data. Using that list, we'll create the data validation list in G2. Then, we'll add a conditional format that will shade rows where the Category value equals the value selected in G2. When applying this to your own worksheets, you might not need all three steps.
First, create a unique list of category values, as follows:
- Select the list of values. In this case, select G4..G46. Be sure to include the header cell (G4).
- Click the Data tab.
- In the Sort & Filter group, click Advanced. In Excel 2003, choose Filter from the Data menu, and then select Advanced Filter.
- In the resulting dialog box, check the Copy To Another Location option.
- The List Range option should reflect the selection ($G$4:$G$49) from step 1.
- In the Copy To control, enter $I$4. You can copy the list most anywhere you like. I chose to copy the list near the data range, so you could see it in the figures.
- Check the Unique Records Only option.
- Click OK and Excel will copy a list of unique category values to column I.
Now you're ready to build the validation list to make the whole process easy and intuitive for the user:
- Select the cell where you want to create the validation list. In this case, that's G2. (I also entered some explanatory text in G1, to help alert the user - this isn't necessary for the technique to work, but doing so helps the user.)
- Click Data Validation in the Data Tools group (on the Data tab). In Excel 2003, choose Validation from the Data menu.
- From the Allow dropdown, choose List.
- In the Source control, enter =$I$5:$I$20.
- Click OK.
With the validation list in place, you're ready to apply the conditional formatting that will create the bands:
- Select the data range. In this case, that's A5..G49.
- Click the Home tab.
- In the Styles group, click the Conditional Formatting dropdown and choose New Rule. In Excel 2003, choose Conditional Formatting from the Format menu.
- In the upper panel, highlight the Use A Formula To Determine Which Cells To Format option. In Excel 2003, choose Formula Is from the Condition 1 control.
- In the Format Values Where This Formula Is True control, enter the following formula: =$G5=$G$2. (There's no option name for this control in Excel 2003.) Pay close attention to the absolute references. If you don't enter the $ symbols correctly, this technique won't work.
- Click Format and then click the Fill tab (Patterns tab in Excel 2003) in the resulting dialog box.
- Choose a color and click OK.
After applying the conditional format, you're ready to put all the pieces together. From the validation list in G2, select any category and watch Excel update the bands, accordingly.
There are a couple of things you'll want to keep in mind when using this technique:
- If you use the ribbon version's table feature, be sure to use a banding color that contrasts with the table's light blue banding.
- Because the unique list of category values isn't dynamic, this technique works best with a static list of values. You'll have to work much harder if you want the validation list to update when you enter a new category value.