ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Maintaining cell reference after sorting (https://www.excelbanter.com/excel-discussion-misc-queries/1083-re-maintaining-cell-reference-after-sorting.html)

GRITS

Maintaining cell reference after sorting
 
Hi Deets LaMoss

I'm having similiar difficulty. Relative cell reference act like an absolute
reference. When the precedent worksheet is sorted the decendant worksheet
reflects the cell reference prior to the sort. My experience has been that by
using relative reference formats =A1 the cell reference would change with a
sort in the precedent worksheet, always giving the same result in the
decendant worksheet. Using absolute reference would force the data to always
reflect what was in the cell referenced. If 10 was in cell A1 and a sort
moved it to A99, the number 10 would still be reported in the linked cell.
Using absolute reference =$A$1, the sort would report whatever data was moved
into the =$A$1 cell. Never had this happen before and have yet to resolve.
i'm wondering if there is a global setting that lock the spreedsheet or if
various format setting cause this problem.

"Frank Kabel" wrote:

Hi
you can't. A link is referring to the cell and not to the content. So
sorting does NOT change the reference. Maybe you could add a unique ID to
each row/record and use VLOOKUP to get the correct record/value

"Deets LaMoss" wrote:

Is there a way to maintain a cell reference after sorting a table? I want to
identify the row number of a specific cell after sorting. I have tried using
"InsertName" with both absolute and relative addresses. Neither one gives
me what I need. I am literate in VB if I need to write a macro.

Thanks in advance.


ExcelBanter AI

Answer: Maintaining cell reference after sorting
 
Hi there,

It sounds like you're having trouble with maintaining cell references after sorting in Excel. When you use relative cell references, they should change with a sort in the precedent worksheet, but it seems like that's not happening for you.

One thing to keep in mind is that when you link to a cell in another worksheet, the link is referring to the cell itself, not the content of the cell. So when you sort the precedent worksheet, the reference in the descendant worksheet won't change.

One workaround for this is to add a unique identifier to each row/record in your table, and then use the VLOOKUP function to retrieve the correct record/value based on that identifier. This way, even if the rows are sorted, the VLOOKUP function will still be able to find the correct record.
  1. Add a unique identifier to each row/record in your table.
  2. Use the VLOOKUP function to retrieve the correct record/value based on that identifier.

As for your question about a global setting that might be causing this problem, I'm not aware of any such setting. It's possible that there's a formatting issue or some other setting that's causing the problem, but without more information it's hard to say for sure.

Formula:

//Sample macro code
Sub SortData()
    
'Sort data in ascending order based on column A
    Range("A1").CurrentRegion.Sort _
        Key1:=Range("A2"), _
        Order1:=xlAscending, _
        Header:=xlYes
End Sub 


Frank Kabel

Hi
in this case it does not matter whether you use a relative or absolute
reference. Sorting will not change the reference in either case.

--
Regards
Frank Kabel
Frankfurt, Germany

"GRITS" schrieb im Newsbeitrag
...
Hi Deets LaMoss

I'm having similiar difficulty. Relative cell reference act like an

absolute
reference. When the precedent worksheet is sorted the decendant

worksheet
reflects the cell reference prior to the sort. My experience has been

that by
using relative reference formats =A1 the cell reference would change

with a
sort in the precedent worksheet, always giving the same result in the
decendant worksheet. Using absolute reference would force the data to

always
reflect what was in the cell referenced. If 10 was in cell A1 and a

sort
moved it to A99, the number 10 would still be reported in the linked

cell.
Using absolute reference =$A$1, the sort would report whatever data

was moved
into the =$A$1 cell. Never had this happen before and have yet to

resolve.
i'm wondering if there is a global setting that lock the spreedsheet

or if
various format setting cause this problem.

"Frank Kabel" wrote:

Hi
you can't. A link is referring to the cell and not to the content.

So
sorting does NOT change the reference. Maybe you could add a unique

ID to
each row/record and use VLOOKUP to get the correct record/value

"Deets LaMoss" wrote:

Is there a way to maintain a cell reference after sorting a

table? I want to
identify the row number of a specific cell after sorting. I have

tried using
"InsertName" with both absolute and relative addresses. Neither

one gives
me what I need. I am literate in VB if I need to write a macro.

Thanks in advance.




All times are GMT +1. The time now is 11:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com