# Highlight the minimum and maximum values for Excel subsets

Excel's MIN() and MAX() function work great, until you want to use them on a subset of data. Consider using this conditional formatting rule.

Excel's MIN() and MAX() functions return the minimum and maximum values, respectively in a range. They're easy to implement when evaluating a complete data set,  but what if you need to know the minimum or maximum value of a subset. For instance, let's suppose you want to know the maximum value for each month in the sheet below. The value 1942 in B6 is the maximum value overall. However, the maximum value for the month of January is 1587, in cell B4. You could use a simple MAX() function for each month, but that's a bit awkward and prone to errors. If highlighting the value works just as well as returning the value, you're in luck. You can use conditional formatting to highlight the maximum value within each month subset, as follows:

1. Select A2:B13 and click the Home tab.
2. Choose New Rule from the Conditional Formatting dropdown in the Styles group.
3. Highlight the Use A Formula to Determine Which Cells to Format option in the top pane.
4. In the lower pane, enter the following formula:
`=\$B2=MAX(IF(MONTH(\$A2)=MONTH(\$A\$2:\$A\$13),\$B\$2:\$B\$13))`
5. Click Format.
6. On the Fill tab, choose a color, and click OK twice. The conditional formatting rule applies the fill color, accordingly!
In Excel 2003, choose Conditional Formatting from the Format menu. In the resulting dialog, choose Formula Is from the Condition 1 dropdown. Enter the formula in step 4. Then, continue with step 5.  Be careful when entering the formula because the mixed referencing is essential to the rule's success. If you're working with a changing data set, use a table so the process is dynamic. (Excel 2007 introduced the table feature, so this won't work in Excel 2003.) To create a table, simply select the range, click the Insert tab, and then click Table in the Tables group. In the resulting dialog, indicate whether your data set includes headers, and click OK. To highlight the minimum value within the month data set, substitute the MAX() function with a MIN() function-otherwise, the formula is the same:

`=\$B2=MIN(IF(MONTH(\$A2)=MONTH(\$A\$2:\$A\$13),\$B\$2:\$B\$13))` ### By Susan Harkins

Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.