Sorting Conditional Formats Properly

Written by Allen Wyatt (last updated March 18, 2020)
This tip applies to Excel 2007, 2010, and 2013


3

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

Setting the AutoRecover Directory

When you are using Word, it normally saves temporary AutoRecover files that reflect the latest state of your document. If ...

Discover More

Selecting a Text Block

Word has an interesting way of allowing you to select a rectangular block of text, without reference to what may be ...

Discover More

Changing the Color Used to Denote Selected Cells

When entering data into a range of cells, the cell in which you are working appears in a different color than the other ...

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)

Alerts About Approaching Due Dates

You may use Excel to track due dates for a variety of purposes. As a due date approaches, you may want that fact drawn to ...

Discover More

Highlighting an Entire Row for the Current Date

It is easy to apply conditional formatting to a cell. What if you want an entire row to be formatted, however, based on ...

Discover More

Highlighting After-Hours Times

The Conditional Formatting capabilities of Excel are powerful. This tip shows how you can use a simple approach to ...

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}] (all 7 characters, in the sequence shown) 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 five more than 3?

2019-03-29 09:26:57

Thomas Morris

Hello, I have followed your instructions but when I remove the rows ($) sign Excel puts them back when I hit apply. Thanks, Thomas Morris


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.