Sorting Conditional Formats Properly

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


1

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

Number Formatting Shortcuts

Keyboard shortcuts can save time and make developing a workbook much easier. Here's how to apply the most common of ...

Discover More

Correcting a Capital Mistake

As you are entering data in a worksheet, Excel can monitor what you type and make corrections for common mistakes. One ...

Discover More

Finding Positions of Formatted Characters in a Cell

With a little bit of work, Excel allows you to format individual characters of the text you place in a cell. If you want ...

Discover More

Dive Deep into Macros! Make Excel do things you thought were impossible, discover techniques you won't find anywhere else, and create powerful automated reports. Bill Jelen and Tracy Syrstad help you instantly visualize information to make it actionable. You’ll find step-by-step instructions, real-world case studies, and 50 workbooks packed with examples and solutions. Check out Microsoft Excel 2019 VBA and Macros today!

More ExcelTips (ribbon)

Automatic Lines for Dividing Lists

When preparing a report for others to use, it is not unusual to add a horizontal line between major sections of the ...

Discover More

Conditionally Formatting Non-Integers

The conditional formatting capabilities of Excel are very helpful when you want to call attention to different values ...

Discover More

Highlighting Cells Containing both Letters and Numbers

Conditional formatting is a great tool for changing the format of cells based on whether certain conditions (rules) are ...

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 8 - 4?

2025-04-20 11:41:56

J. Woolley

Step 5 of the Tip's 2nd method (Advanced Filtering) says, "The List Range should already be filled in, provided you did step 1." This applies only if you previously activated the Filter tool on the ribbon's Data tab as described in the Tip's 1st method (Filtering). Notice the Advanced Filter dialog allows you to put the result in a separate location (which must be on the same worksheet). This means the original data and its neighbors will not be disturbed by hidden rows (filter in-place).
The Tip's 4th method (Formula) also avoids hidden rows; you can even put the formula in a different worksheet or workbook. The Tip's formulas obviously assume the data is on the same worksheet in columns A:F with states in column E. These formulas will sort the filtered results by state (column 5):
    =SORT(FILTER(A:F, (E:E="MN")+(E:E="OK")+(E:E="IL")+(E:E="IA")), 5)
    =SORT(FILTER(A:F, REGEXTEST(E:E, "^MN|OK|IA|IL$")), 5)
Finally, here's an alternate version of the Tip's 5th method (Macro) which matches its 1st method (Filtering):

Sub Display_Addr2()
    'assume data in columns A:F with states in 5th column E
    Range("A:F").AutoFilter Field:=5, Operator:=xlFilterValues, _
        Criteria1:=Array("IA", "IL", "MN", "OK")
End Sub


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.