I have a table of data in excel in sheet 1 which references various different cells in many other sheets. When I try to sort or filter the sheet, the references change when
Even with absolute references, sort does not handle references correctly. Relative references are made to point at the same relative offset from the new row location (which is obviously wrong because other rows are not in the same relative position) and absolute references are not changed (because the SORT omits the step of translating the absolute references after each rearrangement of a row). The only way to do this is to manually MOVE the rows (having converted references to absolute) one by one. Excel then does the necessary translation of references. The Excel SORT is deficient as it does not do this.
Try this method:
I'm pretty sure this can be solved with the indirect()
function. Here's a simplified spreadsheet:
A B C D ...
+------------------------------------------------------+- - - - - - - - -
1 |CITY |Q1-Q3 SALES|ANNUALIZED SALES:(Q1+Q2+Q3)*1.33|
+======================================================+- - - - - - - - -
2 |Tampa | $23,453.00| $31,192.49|
+------------------------------------------------------+
3 |Chicago | $33,251.00| $44,223.83|
+------------------------------------------------------+
4 |Portland | $14,423.00| $19,182.59|
+------------------------------------------------------+
...| ... | ... | ... |
Normally the formula in cell C2 would be =B2*1.33
, which works fine until you do a complex sort. To make it robust to sorting, build your own cell reference using the row number of that cell like this:
=indirect("B"&row())*1.33
.
Hope that works in your situation. It fixed a similar problem I was having.
The easiest method is to use the OFFSET function. So for the original example, the formula would be: =offset(c2,0,-1)*1.33 ="using current cell (c2) as reference point, get the contents of cell on same row, but one column to the left (b2) and multiply it by 1.33"
Works a treat.
For me this worked like below -
I had sheet name references in formula for the same sheet. When I removed current sheet name from the formula and sorted it worked correctly.
this is one good answer to figure out how sorting works from another user and I will add my notes to know how it is not fully correct and what is correct:
The effect on the formula after a sort is the same as copying. A sort does not move the row contents, it copies them. The formula may (or may not depending on the abs/relative references) use new data, just as a copied formula does.
My point is that if the formula can be copied from 1 row to another and the effects don't change, the sorting will not affect the formula results. If the formulas are so complex and so dependent on position that copying them changes the relative contents, then don't sort them.
And my note that I experienced in practice:
The above user is saying right but in fact It has some exception: parts of a columns formula containing sheet name (like sheet1!A1) are treated as absolute references (in spite of copying that changes the references if they are relative ) so that part of formula will be copied without changing references relative to changing the place of formula This includes current sheet cells addressed fully like : sheet1!A2 and will be treated as absolute references(for sorting only) I tested this of excel 2010 and I do not think this issue be solved in other versions. The solution is to copy and past special as value in another place and then use sorting.