excel cell locations based on value in another cell - excel-formula

I am using Excel 2010. I would like to be able to use the value of a cell (such as the value in cell A1) in a function that will define the location to get data from another spreadsheet.
='Sheet1'!$B$xx (where the value of xx is defined in cell A1)

You can use Index, preferable to use INDEX as it is less volatile.
=INDEX(B:B,A1)
This returns a value or the reference to a value from within a table or range

That can be done with Indirect(). Note that Indirect() is volatile and using it much can slow down large workbooks.
=Indirect("Sheet1!$B$"&A1)
Another (non-volatile) option is to use Index, like this
=INDEX(Sheet1!B:B,Sheet2!A1)

Related

How do you find the max in a particular cell across all sheets and return a different cell?

I have been able to return the max value of F1 from all sheets by using this formula located in cell G13:
G13=MAX(ABC:XYZ!F1)
Now I also want to return the value of A5 from the sheet where the MAX was found in G13.
How do I write the formula for that?
TIA.
A non-volatile alternative, which references the maximum value you have already calculated in cell G13:
=INDEX(FILTERXML("<a><b>"&TEXTJOIN("</b><b>",,ABC:XYZ!A5)&"</b></a>","//b"),MATCH(1,FREQUENCY(G13,ABC:XYZ!F1),0))
Create a named range that includes all the sheet names.
Then using INDEX/MATCH and INDIRECT inside MAX and SUMIFS we get:
=INDEX(INDIRECT("'"&TRANSPOSE(Sheets)&"'!A5"),MATCH(MAX(INDIRECT("'"&TRANSPOSE(Sheets)&"'!f1")),SUMIF(INDIRECT("'"&TRANSPOSE(Sheets)&"'!F1"),"<>"),0))
Depending on one's version one may need to use Ctrl-Shift-Enter instead of Enter.
The HERE is coming from Sheet2!A5 where Sheet2!F1 has 1000 in it. All other sheets have 1 in F1

Turn a static table to dynamic

I'm looking for a formula (without lambda function by preference) that could turn a static table to dynamic table.
For example, Column B contains raw data. I'm looking for a formula in D3, which contains B3 or e.g., B3:B1000 (to largely cover the area), such that it returns a dynamic array which is all the data below B3 until a blank cell. Then, in another cell, formulas like =D3# spill well.
Does anyone have a good idea?
=B3:INDEX(B:B,MATCH(1,(B:B="")*(ROW(B:B)>3),0)-1) works without sequence, so compatible for Excel prior to office 365. (To be entered with ctrl+shift+enter then) also this is non volatile (OFFSET recalculates at every change in sheet).
One possibility is to use INDEX, SEQUENCE, XMATCH, and ISBLANK.
=INDEX(B3:B1000,SEQUENCE(XMATCH(TRUE,ISBLANK(B3:B1000))-1))
Is this what you are looking for?
Formula in D3 is:
=OFFSET($B$2,1,0,MATCH(0,COUNTIFS(B$3:B$1000,B$3:B$1000),0)-1,1)
MATCH in combination with COUNTIFS is used to determine the position of the first blank cell
OFFSET delivers the rows from the beginning to the blank cell.

Excel - Reference a column for a formula, using input from a cell

I am trying to further my knowledge in excel, I have searched around all day for an answer to my current question but I was unable to find anything relating to my needs.
I basically, want to know if it is possible to reference which column a formula should use, by storing it in a cell.
So if I have a formula which is using column - Test!C:C, am I able to store that string in a cell and reference that cell in the formula? I have many formulas which are using the same reference, so if i decide to change what column i want to utilize, it takes some time to remove them all.
I know i can use replace all, but it would be fantastic if there was a method to reference a column via a cell.
Use the Indirect Function:
If the cell in which you put the column Address "Test!C:C" was A1, you would use:
=INDIRECT(A1)
If the sheet never changed and you only wanted to reference the column. So in A1 you only want to put "C":
=INDIRECT("Test!" & A1 & ":" & A1)
Indirect lets you enter a string that is then used as a reference.
There is one major draw back to the INDIRECT() function, it is volatile. This means that it will calculate every time excel calculates, not only when the reference cells change. So depending on the number of formulas, it will slow the calculation times.

Obtain entire array from a single cell that is part of a collection of cells containing the same array formula?

It's probably best if I explain this with an example...
Say we have in a worksheet cells A1:C1 containing the values [1,2,3].
I want to take the square of each of these numbers but I do this using a cell-formula so in cell A2 I have {=A1:C1^2}. This is an array-formula. However, if I only press ctrl+alt+enter in cell A2, I see the first element of the array squared (i.e. A1^2 = 1^2 = 1).
If I select all of A2:C2 hit ctrl+alt+enter it expands out the entire array-formula across the three cells and we see the result of [1,4,9].
What I want is to only have to place the array formula in cell A2 and write VBA to be able to access the entire array for the entire operation (i.e. A1:C1^2).
I don't want to execute the function again in VBA as the array must already be stored in memory when we execute {=A1:C1^2} in cell A2 so how can I get the entire array result from a single cell that is part of a larger array?
Note: this is just an example, I plan to do this for large, unknown sized arrays.
Excel cells can only contain scalar values, so what you want to do is not possible without using EVALUATE in your VBA to execute the formula from A2.
And you need to be careful how you use EVALUATE: it has many peculiar quirks.
(see my blog post on EVALUATE )
Excel computes the entire array and displays what it can. This is based on what cells the user selects prior to the array confirmation.
Charles is correct in his answer. There is no way to get at the array without recalculating it with Evaluate(), like so:
MsgBox Join(Evaluate([a2].Formula))
VBA does have the HasArray property for the range object, and in your example with [a2] being the sole cell in the array formula, the HasArray property will return True.
Unfortunately, there is no corresponding GetArray property, which is exactly what you are after.
My take is that Excel's worksheet calculation engine does indeed maintain the array in memory, but this is a separate construct form the range and cells and VBA has no access to it.

Reusing of formula driven result in a if statement in excel

=IFERROR(IF((INDEX(named range1,MATCH(named range2&A1,named range3,0)))<>"",INDEX(named range1,MATCH(named range2&A1,named range3,0)),"-"),"")
Here in this formula I am trying to vertical lookup a value using index-match and checking it within a if statement for blank value.If it is not blank I am using the non-blank value to set it in a given cell.
How can I optimise my formula to reduce performance overhead in excel.
I don't want to use vba for this by storing the result in a variable
The most time consuming bit is the Match(), so avoiding a duplication of the same Match is key. You can
place the Index/Match in a helper cell and then use the formula
=IFERROR(IF(B1<>"",B1,"-"),"")
This way the Index/Match will be calculated only once.
place the Match into a named formula. If you keep your wits about you, named formulas can work with relative cell references. Select the cell where you want the formula to go, then create a named range "NamedRange4" with the formula
=MATCH(named range2&A1,named range3,0)
Then use this formula in the selected cell:
=IFERROR(IF((INDEX(named range1,NamedRange4))<>"",INDEX(named range1,NamedRange4),"-"),"")
The Match will be calculated only once and the result stored in the named range. With relative cell referencing of NamedRange4, the IfError formula can be used in other cells with correct results.

Resources