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

Squeezing Everything In

Do you have just a line or two of text that "spills over" onto another printed page? Here are some ways you can compress ...

Discover More

Using the MROUND Worksheet Function

If you want to round a value to some multiple of a whole number, you'll want to become familiar with the MROUND function. ...

Discover More

Grouping Drawing Objects

Drawing objects are easily added to a document. You can group these objects so they are easier to manage by following the ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Coloring Identical Company Names

Want to know where duplicates are in a list of names? There are a couple of ways you can go about identifying the ...

Discover More

Converting Conditional Formatting to Regular Formatting

Conditional formatting allows you to change how information is displayed based on rules you define. What if you want to ...

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 ...

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 one less than 9?

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.