Sorting Conditional Formats Properly

by Allen Wyatt
(last updated April 18, 2015)

2

Andre has a table of data that includes some conditionally formatted cells in column M. The formatting is based on conditions in cells of the same row in columns G and H. When he sorts the table, the conditional formatting seems to stay with the original row. Thus, if the original cell was M10 (tied to cells G10 and H10), after the sort the cell ends up in M7, but it is still tied to G10 and H10. It should, instead, now be tied to G7 and H7. Andre wonders how he can get Excel to sort his conditional formatting references properly.

This problem is most likely related to how your referencing is done in your conditional format rules. Typically, when you reference cells when setting up a rule, Excel defaults to absolute referencing. In other words, your rule may look something like this:

=AND($G$10=1, $H$10=1)

The dollar signs indicate that whatever follows (either the column reference—G or H—or the row reference—10) is absolute and should not be modified by Excel. This means that when the rows are sorted, the references in the rules are not modified and they will still point to the original rows. If you want the references to change, then you'll need to modify the rules to remove the dollar signs before the row references:

=AND($G10=1, $H10=1)

It is not necessary to remove the dollar signs from the column references because your sorting isn't modifying those column references.

If you are still running into problems with the rules after sorting, it is possible that not all your data is getting included in the sort. This is particularly true if you leave it up to Excel to select your data table automatically for the sorting operation. Make sure you select the entire data table before sorting and this should solve the problem.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9951) applies to Microsoft Excel 2007, 2010, and 2013.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

A Quick-and-Dirty Word Count

Word provides a tool that counts the number of words in a document. Here's an alternative method of calculating the number of ...

Discover More

Ctrl+V Pasting is Flakey

When you copy and paste a formula, you usually want to see the formula where you pasted. If you don't get the formula, but ...

Discover More

Word Count in Multiple Selections

Getting a word count for an entire document is easy. What you may not know is that some versions of Word can also provide ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Changing Shading when a Column Value Changes

If you have a data table in a worksheet, and you want to shade various rows based on whatever is in the first column, then ...

Discover More

Protecting Your Conditional Formatting Rules

If you have conditional formatting applied in a worksheet, the formulas in those formats may not be as secure as you would ...

Discover More

Conditionally Highlighting Cells Containing Formulas

Excel's conditional formatting feature allows you to create formats that are based on a wide variety of criteria. If you want ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is four less than 9?

2015-04-20 08:40:58

Simon Graffe

The proposed solution does not work.

The conditional format applies to "$M$10" and there is no way to change it, so the rule reads:

Formula: =AND($G10=1, $H10=1)
Applies to: =$M$10

Sort the data, open the Manage rules dialog box, and the rule reads exactly the same. So, when your data is in row 7 after the sorting, it will not be formatted.

The "Applies to" box could be changed to: =$M$7:$M$100 (include all data in column M) and the rule will apply to all the column, and it will appear it is working, but the original problem asked for SOME rows to be conditionally formatted, not ALL of them.

The solution would be to add some specific data to the row, and include it in the formula. That specific row data would be sorted along with the data, and the rule will work.

This solution works:
Formula: =AND($C7="Format10", $G7=1, $H7=1)
Applies to: =$M$7:$M$13

In this case, the data rows include rows from 7 to 13. The formula refers to the first row (7) of data, and the Applies to formula refers to the M column, not just one cell. The "Format10" value should be added at column C to the row that should be formatted.


2015-04-18 08:05:41

Sicco Jan Bier

When you create a reference, it pays off to toggle and connect the absolute cell reference with F4. It will suggest absolute, row, column and relative reference when you hit F4 repeatedly.

Using defined names for ranges is another way to make the reference fixed, while keeping all elements within the range available (depends on the formula to use). Especially for lists and lookups.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.