Excel calculates formulas based on wrong dynamicly defined sheet - excel

I have the following formula on various sheets in an Excel workbook:
=SUM(SUMIFS(INDIRECT(CONCATENATE("'",REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),"")," HR","'!$e:$e")),INDIRECT(CONCATENATE("'",REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),"")," HR","'!$q:$q")),I$13,INDIRECT(CONCATENATE("'",REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),"")," HR","'!$j:$j")),{"שעון","בתפקיד","עבודה מהבית"}))
the formula takes the name of current sheet, concatenates the string " HR" to it and goes to a range of cells in sheet named as the concatenated string.
It performs a few calculations on the data there and returns the value.
For some reason the cells in different sheets that contain the "same" volatile formula show me the values that would come up in another sheet.
To see the right value I must enter only one of the formulas boxes in a relevant sheet, press enter and the evaluation turns to be correct.
I tried formula evaluation and theoretically it shows me the right calculation process on every sheet.
Any suggestions? Could it be some evaluation issue that is not related to formulas correctness?

You expect CELL to return information on the current cell when no reference is given, but it does not. CELL returns values based on the ACTIVE cell -- the cell that is active at the time of the calculation. Every time the cell recalculates, it will look at the active cell at that time, which may be on another sheet.
To see this in action, use the formula =CELL("address")&" "&TEXT(NOW(),"hh:mm ss") Since NOW is volatile, the cell will be recalculated every time you edit a cell. Edit any other cell, and you will see the address of that cell and the time it was calculated.
You will almost always want to include a reference value, eg CELL("filename",A1) To get the expected behavior, you'd just use a relative reference to the current cell.

Related

Making the Indirect formula more dynamic by making it change the row (cells) referenced in the formula

I have three excel sheets that are set out the same (they are filled with the same tables but have different values). I have now created another excel sheet which is suppose to sum the values at each cell. For example, take cell G10. All values in this particular cell, across these three excel spreadsheets are summed and presented in this new summary excel sheet. I have created the following ‘indirect’ formula to do it. (I want to use indirect formula as it refers to the name of each worksheet. It is appropriate for this workflow).
Equation (at cell G15)
=SUM((INDIRECT($G$2&"!G15:AV15",TRUE)),(INDIRECT($G$3&"!G15:AV15",TRUE),(INDIRECT($G$4&"!G15:AV15",TRUE))))
($G$2, $G$3,$G$4refers to the worksheet name;
G15:AV15 refers to the particular range…)
The formula works for the particular row, however I want to be able to copy and paste this formula to other cells below and get excel to recognise and change the row number accordingly…
Ie when I copy this formulae to cell value G20, I would want the formula change to reference “G20:AV20.” Does anyone have any recommendations??

How to make an INDIRECT formula but with adjusting ranges

I'm hoping someone can help me make better use of the INDIRECT formula.
I have a list of sheet names in a table and an INDIRECT formula that uses that list to return a value in a specified cell - the list of sheet names is just an easier way for me to drag the formula down the table and read the appropriate cells without having to manually link each sheet.
=INDIRECT("'"&A2&"'!"&"K10")
This works fine for single cells as the range ref is simply stated as the text in the formula (K10), the problem arises when I need to start referring to a range such as K10:K15 and summing the values.
The range K10:K15 will inevitably have new rows added or deleted on the relative tab and as INDIRECT is using text as the reference it means the range doesn't automatically adjust - this is as I understand it one of the 'benefits' of INDIRECT but in this case is actually holding me back.
Also worth noting that the range (K10:K15) may move as rows are added/deleted above this, as this range is part of a larger table.
In simplistic terms I want to achieve the same result as a standard reference to a range on another sheet, e.g. =sum(sheet1!K10:K15) (as this will adjust when rows are added/deleted) but I just want to be able to dictate which sheet is referred to via a list I have in a table on a summary sheet.
How do I either write INDIRECT so the range adjusts when new rows are added/deleted or is there a different formula I should be using that achieves this?
Any advice greatly appreciated :)
=INDIRECT("'"&A2&"'!K"& MATCH(TRUE,INDIRECT("'"&A2&"'!K:K")<>"",0)&":K"&MAX((INDIRECT("'"&A2&"'!K:K")<>"")*(ROW(INDIRECT("'"&A2&"'!K:K")))))
This indirectly references the rows from the first non empty cell up to the last non empty cell in given sheet in column K. Not sure if you need to enter with ctrl + shift + enter (not in the app version).
Note: If the range contains empty cells in between the first and last non empty cell it will be included as value 0
Or in office 365 use the following:
=FILTER(INDIRECT("'"&A2&"'!K:K"),INDIRECT("'"&A2&"'!K:K")<>"")

Graph formula references error

I am trying to create a graph with the help of Name Manage. I have come up with the following formula to create the series of numbers required by me. The formula is:
Sheet2!B4:INDIRECT(ADDRESS(4,Sheet3!AM11,4,,"Sheet2"))
When I input this formula into the cell it works properly and provide me with required series, but when I create the name(using name manager) of the series with the same formula and try the create the graph the excel throws the following error:
Several things:
thing one: you are using relative cell references in the named formula. That means that wherever the active cell is, the named formula will recalculate based on the current cell. B4 will change to any cell based on the current cell. Use absolute references like $B$4if you want to anchor a certain cell as a base reference.
Thing two: Indirect with a complicated nesting of functions that reveal a row and/or column can be replaced by a more efficient Index formula.
Thing one is probably the thing that causes your problems, because the result of the formula will change with the selected cell.
Edit after inspecting the workbook
The problem is definitely the relative cell references, and making them absolute definitely solves the problem. Your formula was defined with the active cell in B10 and it is
=Sheet1!B1:INDIRECT(ADDRESS(1,Sheet1!D10,4))
But when the active cell is in A1, for example, the formula changes to
=Sheet1!A1048568:INDIRECT(ADDRESS(1,Sheet1!C1,4))
Every time you click on a cell, the named formula will recalculate based on the position of the current cell. That's why you need absolute references. You can correct your formula to
=Sheet1!$B$1:INDIRECT(ADDRESS(1,Sheet1!$D$10,4))
Or you can use Index instead of Indirect this way:
=Sheet1!$B$1:INDEX(Sheet1!$1:$1,Sheet1!$D$10)
Or you can use a simple Offset function
=OFFSET(Sheet1!$B$1,0,0,1,Sheet1!$D$10-1)
Whichever formula you prefer, this will always deliver the correct range, no matter which cell is the active cell.
Once you have the date range in place, you can use a simple offset from the date range to get the series ranges.
Offset by one row for Open, offset by two rows for High, etc.
=OFFSET(Date,1,0)
The screenshot shows the Date formula with the Offset function and you can see the formulas used for the Open, High, Low, and AdjClose names. The chart shows the series Open and AdjClose. Note how the marching ants highlight the current extent of the named range. The Date name will always refer to a range starting in B1 because that cell is anchored with an absolute reference.
If you have any questions about that, pipe up.

VLookup Range Change when shifting and deleting columns in the range of the Vlookup function

I have the following search function:
=ALS((VERT.ZOEKEN(B6;'Raw Data'!$H$1:$BB$3000;21;ONWAAR))=100;"Winkel";
ALS((VERT.ZOEKEN(B6;'Raw Data'!$H$1:$BB$3000;21;ONWAAR))=400;"Woning";
ALS((VERT.ZOEKEN(B6;'Raw Data'!$H$1:$BB$3000;21;ONWAAR))=500;"Parkeerplaats";
ALS((VERT.ZOEKEN(B6;'Raw Data'!$H$1:$BB$3000;21;ONWAAR))=200;"Kantoor";
ALS((VERT.ZOEKEN(B6;'Raw Data'!$H$1:$BB$3000;21;ONWAAR))=600;
"Antenne";"Overig")))))
But when I change and delete some of the columns in the range of the Vlookup search with a macro (Vert.Zoeken=Dutch for Vlookup) The Range specified within the formula changes.
Why does it do that, and how do i stop it? I Couldn't find a clear answer anywhere else.
(The macro code just deletes some columns, and doesn't do anything else really)
Cell ID vs Cell Location
One of Excel's primary mechanics is that each cell effectively has its own "ID", which is represented by that the location of that cell at the time that it was referenced. The location of that cell can change, when columns & rows are manipulated.
For example: in A1, make the formula
=B5+D3
Then insert a row above row 3, and a column to the left of B. Your formula will now read:
=C6+E3
You'll notice that because the locations of the unique cells was changed, the formula accounted for that. This feature is incredibly useful, as otherwise, even simply formulas would need to be completely re-written if a new header was inserted above some numbers.
If you want the position of a reference to be "absolute" in the sense that it always points to the same location instead of the same cell ID, then you have a few options:
VBA solution to ignore this feature
By its nature, VBA code does not automatically adjust when cell references change. If you have a formula which references Range("B5"), then it will still say Range("B5") after you insert a new column to the left of B. In this way, you could use VBA to build the formulas within your worksheet. ie: VBA could re-write the formulas to reference the columns you want it to.
Excel solution to ignore this feature
To solve this without VBA, meaning your VBA code would not need to re-write the formulas, you could use the INDIRECT function. INDIRECT allows you to dynamically determine what a cell reference is, based on building a text string of a location. For example:
=VLOOKUP(A1,INDIRECT("B"&5+10&":D100"),2,0)
This will create the text string "B15:D100", and that will be the range referenced by VLOOKUP. Because you have entered the "B" & "D" as text values, they will not change when you insert rows/columns.

Find and "copy" a range to a new sheet

I have data that comes in into a sheet in certain time intervals, but every time the order might be different. So now, I want to "copy" the values from the "unsorted" sheet, to a new sheet which is sorted in the order I would like the data to be. From here on, calculations can be done using fixed references when referring to the "sorted" sheet.
Here is what I've done so far:
Determine the location of the label of the needed subset of the data in the unsorted sheet.
Determine where the actual needed data is on the sheet (the label is above the data, and one column to the right, so the data is one row down and one column to the left, and goes on for 32 columns and down 24 rows).
Now I want to do this step:
Use a array formula (CSE function) to reference those cells, as seen in this screenshot:
Trying to copy using CSE reference
Hitting Ctrl+Shift+Enter shows the result: #REF
What can I do differently?
Based on the feedback by #tigeravatar:
I referenced the range to the ASTIR sheet incorrectly:
in cell K13 is an invalid reference of "ASTIR!$A$5:ASTIR!$AF$29". You
don't need the sheet name twice, which is what's causing the #REF!
error.

Resources