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

Limiting a Spelling Check

When you perform a spelling check, Word typically checks everything in your document. If you want to limit what is checked, ...

Discover More

Selecting a Chart Pattern

If you don't have Excel installed on your system, Microsoft Graph is a handy way to create simple charts for your documents. ...

Discover More

Changing Directories in a Macro

Need to specify which directory on your hard drive should be used by a macro? It's easy to do using the ChDir command.

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Turning a Cell Red when a Threshold is Exceeded

Excel provides a great conditional formatting capability that allows you to change how a cell appears based on critiera you ...

Discover More

Highlighting Cells Containing Specific Text

If you want to highlight cells that contain certain characters, you can use the conditional formatting features of Excel to ...

Discover More

Deleting Conditional Formatting

After you've applied a conditional format to a cell, you may have a need to later delete that format so that the cell is ...

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. 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 three minus 2?

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.