Written by Allen Wyatt (last updated March 18, 2020)
This tip applies to Excel 2007, 2010, and 2013
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.
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!
When preparing a report for others to use, it is not unusual to add a horizontal line between major sections of the ...
Discover MoreThe conditional formatting capabilities of Excel are very helpful when you want to call attention to different values ...
Discover MoreConditional formatting is a great tool for changing the format of cells based on whether certain conditions (rules) are ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments