Written by Allen Wyatt (last updated April 26, 2025)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365
In his data, Larry has a named range that refers to cell C7. If he sorts the data, the value that was in cell C7 is now in cell C15. Larry would like the named range, after the sort, to refer to cell C15, but it still refers to cell C7. He wonders if there is a way to make a named range refer to the value in a cell (so it travels with the value) rather than to the cell itself.
No, there is no way to do this in Excel. When a name refers to a range (thus, a "named range"), then it always refers to that range, even after sorting. The range hasn't change, after all—just the values within the range have changed.
There are ways around this, however. The key is to remember that Excel allows the naming of more things than just cell ranges. Names can refer to ranges, values, or formulas. It is telling that Larry is using a named range to refer to a single cell, not a multi-cell range. Since Larry wants to always refer to the value that is originally within cell C7, he can use a name to refer to the value instead of to the cell containing the value.
Let's say that cell C7 contains a static value, such as 5 or 23 or 123.45 or "apple" or "blue." In that case, you can simply assign the value to a name, in the following manner:
Figure 1. The New Name dialog box.
Now you can use the name anywhere in the worksheet that you want. For instance, let's say that in step 4 you entered the value 23. With the name defined, you could use the following formula anywhere you want to get the result of 37:
=MyValue + 14
If you later need to change the value associated with the MyValue name, then you can use the Name Manager (within the Defined Names group of the Formulas tab of the ribbon) to modify the value. Of course, if you are doing that, and especially if you need to modify the value often, then it makes sense to rethink the logic of your worksheet. In that case, it would make sense to define a static data entry area. Then, you can refer to the cells in that data entry area in your main data. Sort the main data, and the data entry area is not affected. This approach bypasses using named ranges (or named values) completely.
If you want to stick with names, remember that they can also be associated with formulas. For instance, Larry indicated that the value he wants to always have associated with the named range is in column C. (Larry says it starts out at cell C7.) Further, let's assume that the value within cell C7 is 123. Using the steps already defined above, in step 4, place the following into the Refers To box:
=INDEX($C:$C,MATCH(123,$C:$C, 0))
Now whatever name you created (for instance, MyValue) will return the value 123, provided the value appears in column C. If the value is not in the column, then MyValue returns #N/A. Since sorting simply reorders the values within column C, then the value that started at cell C7 (123) can now be at a different location (perhaps cell C15), but the MyValue name will always return 123 because the value is still within column C.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10252) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2019 For Dummies today!
Moving between to adjacent worksheets is easy; Excel provides a shortcut key to do the trick. If you want to move between ...
Discover MoreExcel has several features that cannot be customized. The font size in the drop-down lists is one of them. If you need ...
Discover MoreExcel tries to anticipate what you want to type into a cell, particularly when it comes to entering formulas. Here are ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2025-04-28 14:51:49
J. Woolley
I believe this issue arises only when sorting a range of cells that have constant values. If one of those cells is tagged with a comment, that comment will stay with its cell while the cell's value is sorted; therefore, the comment can be used to locate the cell and its value.
My Excel Toolbox includes the following function to return the first cell on a worksheet that has a legacy unthreaded comment (Note) with text containing a specified Substring:
=CellByComment(Substring, [CaseSensitive], [SheetRef])
If optional CaseSensitive is FALSE (default), alphabetic case of Substring is ignored; otherwise, comparison of Substring with each comment's text will be case-sensitive. If optional SheetRef is omitted, comments on the cell formula's worksheet will be searched for Substring. To find a cell on a different worksheet, SheetRef must be a cell or range on that sheet. If no cell is found, the function returns #REF! (Error 2023).
Here are some examples:
=CellByComment("Tag #1") -- returns the value of a cell with "Tag #1" in its comment's text
=CellByComment("JW", TRUE) -- returns the value of a cell with "JW" in its comment's case-sensitive text
=CellByComment("my cell", , [Book1.xlsx]Sheet1!$A$1) -- returns the value of a cell on Sheet1 of Book1.xlsx with "my cell" in its comment's text
=CELL("address", CellByComment("local") -- returns the address of a cell with "local" in its comment's text
Here's an abbreviated version:
Function CellByComment(Substring As String) As Variant
Dim item As Comment
For Each item In Application.Caller.Worksheet.Comments
If InStr(item.Shape.TextFrame.Characters.Text, Substring) > 0 Then
Set CellByComment = item.Parent
Exit Function
End If
Next item
CellByComment = CVErr(xlErrRef)
End Function
See https://sites.google.com/view/MyExcelToolbox/
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