I'm trying to create a formula that will take the contents from a cell on a different sheet. I don't want to just give the direct cell reference, because I want to be able to cut & paste this into different places and refer to a reference number to know which cell to get.
So, I'm using the Cell() function. But, when I enter something like =CELL("contents", Sheet1!A2), it returns the value of A2 on the current sheet, not on Sheet 1. Every other function I've tried recognizes Sheet 1 when it is given. (This example is just a trial. In reality I have to use Concat() & Indirect() to create the cell reference).
If it matters, I'm using Excel365
Related
I also need to get your help for the same issue. I need to copy the cell values and not the formulas automatically to the other Cell, "automatically" meaning, I don't need to click, use mouse, or any other means to do that, like once theres a value on that specific cell (which is derived from a formula), the value will automatically be copied and pasted in the other cell (without any intervention from my part) (Only the value is copied not the formula)
Note:
The cell should contain only the copied value and not the formula.
Scenario:
A1 Cell : has 250 value
B1 Cell : has a vlookup formula to search for the value of A1 cell (I need to use VLOOKUP as there's a lot of items in the list, and it is "Dynamic", the reason I cannot just use formula "=A1" to get the value directly)
C1 Cell : Needs to copy and paste only the plain value from B1 cell which is 250, not including the vlookup formula, it should be automatically copied without any intervention (Cannot use VBA code / Macro as it will be run in excel online)
Thanks!!
Just use abasic Excel formula.
Example:
The source data is in cell A1.
You want to copy the same value to cell B1.
In cell B1 write:
=A1
That is all.
Additionally, you need to configure correctly the strategy for calculating the formulas:
I managed to find a solution, sharing as might help someone in the future, just needed to use =value(A1), instead of just "=A1", when I did this, the chart can read the values as it is and not the formula behind it. Found another work around as well, by using the formula =A1+0, for some reason this works too. –
=value(A1) works perfectly , If that formula contains a % figure , simple We can multiply by 100 to get the correct value.
My P11 cell references another cell:
=J14
And I want to reference the reference in the P11 cell in multiple other cells. EX:
=OFFSET(J14,0,-4)
=OFFSET(J14,0,1)
=OFFSET(J14,0,2)
Except the "J14" in the OFFSET formula would ideally have a reference that grabs the reference of the P11 cell because I'm going to need to change that reference every time I do it. It would therefore be helpful to grab the reference of the P11 cell so that I only need to change the reference of one cell instead of 4.
I spent about an hour googling this but I just can't seem to find anything. If you guys could help that would be great because I just can't find a solution!
Assuming in cell P11 you have the formula =J14 you can use a combination of FORMULATEXT, INDIRECT, and SUBSTITUTE to get the cell reference. I am assuming the formula in cell P11 will only ever be a reference to a single other cell (e.g. =J14 or =M10 or =N14). If this is not true and the formula will ever be more complex than referencing one cell, this method will not work.
First we can use =FORMULATEXT(P11) to get the text of the formula in cell P11. The result of this is =J14. In order to be a valid cell reference we must remove the equal sign, which we can do by applying the SUBSTITUTE function like this:
=SUBSTITUTE(FORMULATEXT(P11),"=","")
The result of this is J14 which is a valid reference we can pass into the INDIRECT function to get what we are ultimately after.
So finally, in each of your offset formulas you would have:
=OFFSET(INDIRECT(SUBSTITUTE(FORMULATEXT(P11),"=","")),0,-4)
=OFFSET(INDIRECT(SUBSTITUTE(FORMULATEXT(P11),"=","")),0,1)
=OFFSET(INDIRECT(SUBSTITUTE(FORMULATEXT(P11),"=","")),0,2)
The benefit of this method is that you only need to change the formula in cell P11 and it does not rely on intermediate cells.
I hope this helps, if it doesn't and you can clarify your issue I can give another try.
You would want to use the INDIRECT() in conjuntion:
In another empty cell, lets say Q11 you would put in the cell reference as a string P1.
Then the following formulas in their various cells:
=INDIRECT(Q11)
=OFFSET(INDIRECT(Q11),0,-4)
=OFFSET(INDIRECT(Q11),0,1)
=OFFSET(INDIRECT(Q11),0,2)
A couple of words about these two formulas, they are Volatile functions. That means that they recalculate every time excel recalculates whether the data to which they refer change or not. So if you have a sheet full of them it will make a noticeable change in the calculation times. Only have four would not be noticeable.
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.
I have the names of the tabs/worksheets (M-61,M-62,M-63W) at the top row (A1, B1, C1...etc)
I am trying to get a sum of several cells within the different sheets:
=SUM('M-60'!H21,'M-60'!H43,'M-60'!H86,'M-60'!H87,'M-60'!H97,'M-60'!H98)
However, right now I’m referring to the sheet itself, and have to apply the same formula to all the other sheets. This will require me to manually go and change all the sheet titles accordingly.
I was wondering if there is any way to reference the top row with the sheet titles within the formula so it automatically refers to the row text instead of me having to manually change the sheet title.
Edit
Now i got the reference to work, just wondering how would I do a sum of several cells in that tab
=INDIRECT("'"&$F1&"'!H87",TRUE)
Maybe:
=SUM(INDIRECT("'"&C1&"'!H21"),INDIRECT("'"&C1&"'!H43"),INDIRECT("'"&C1&"'!H86:H87"),INDIRECT("'"&C1&"'!H97:H98"))
(though there may well be a much smarter way).
You can use the INDIRECT function, which uses a string as an argument and converts it to a range. So
=M-60'!H21
is the same as
=INDIRECT("M-60'!H21")
or, if Sheet name is stored in, say, cell C1:
=INDIRECT(C1&"'!H21")
Your example has a SUM, though, which requires some adaptations. This your example:
=SUM('M-60'!H21,'M-60'!H43,'M-60'!H86,'M-60'!H87,'M-60'!H97,'M-60'!H98)
Since you are not using a range, you can convert that SUM into simple addition. Assuming Sheet name in cell C1
=INDIRECT("'"&C1&"'!H21")+INDIRECT("'"&C1&"'!H43")+INDIRECT("'"&C1&"'!H86")+INDIRECT("'"&C1&"'!H87")+INDIRECT("'"&C1&"'!H97")+INDIRECT("'"&C1&"'!H98")
This should solve your problem. More info here
By the way, if you were using a range, the OFFSET function with INDIRECT as an argument would work. But that's not necessary here.
In an excel workbook, I'm referencing a defined name from another tab (to get dependent data validation). Accessing the defined name directly works, but accessing it through INDIRECT doesn't.
=INDEX(DefinedName,1) returns the first value of the range
=INDEX(INDIRECT("DefinedName"),1) returns #REF!
I have also tried
=INDEX(INDIRECT("SheetName!DefinedName"),1), but it also returns #REF!
Sample file can be downloaded here.
Thomas,
I hadn't come accross this before.
It appeas that INDIRECT and dynamic range names are incompatible. There is a useful reference here from Dicks blog
Not quite an answer, but it may have something to do with the fact that your named range is returning an array instead of a cell reference (in this case {"VALL";"GENADMIN";"HOSP";"CELLAR"}).
You can replicate the error by removing the named range and replacing it with its actual formula, and then F9'ing the formula:
=INDIRECT(OFFSET(Defaults!$C$1,1,0,COUNTA(Defaults!$C:$C)-1))
=INDIRECT({"VALL";"GENADMIN";"HOSP";"CELLAR"})
Since Excel is expecting some sort of reference to a sheet range, it is failing here since it can't resolve the array to anything specific (pressing F9 again yields ={#REF!;#REF!;#REF!;#REF!}).
The INDEX formula works because it can handle the array reference:
=INDEX(OFFSET(Defaults!$C$1,1,0,COUNTA(Defaults!$C:$C)-1),1)
=INDEX({"VALL";"GENADMIN";"HOSP";"CELLAR"},1)
={"VALL"}
Not an expert, but that's my best crack at it.
This absolutely will work. Maybe they were incompatible in 2012, but they certainly work in 2018. I imagine it would have also worked in 2012 if used correctly.
The INDIRECT function attempts to turn TEXT into a range reference. That TEXT must be a valid reference.
A named range is already a Range Reference. There is no need to get a reference from a reference. This is why the OP example works without using INDIRECT.
A more likely implementation would be if you had the value "DefinedName" from the OP, or any named range in a cell. Then point INDIRECT to that cell where it find plain ol' text. Then it turns that text into a range reference.
You can even use formulas in the INDIRECT to modify the reference. A common approach might be to have a Sheet name in a cell and then use INDIRECT to pull data from various sheets. This is primarily useful when you want to copy and paste formulas and have the sheet (or cell) reference dynamically adjust to a new target.
Setup
Start with a blank workbook which should contain three blank worksheets, (Sheet1, Sheet2, and Sheet3) If not, get to that point. Then enter the following basics:
Sheet 1
Cell A1, enter "Range Reference"
Cell A2, enter "SUM from Sheet"
Cell B1 enter "Sheet2!A1:A4" (Note there is no "=" This text is a range reference.)
Cell C1, enter "THIRD_SHEET" (This text is equivalent to a named range we'll create in a second.)
Then in Sheet2,
Cell A1, enter 1
Cell A2, enter 2
Cell A3, enter 3
Cell A4, enter 4
In Sheet3
Cells A1-A4 enter 100 through 400 respectively.
Then create a named range called "THIRD_SHEET" which refers to cells A1-A4 on Sheet3.
Try
In Sheet1:
Cell B2, enter the formula:
"=SUM(INDIRECT(B1))"
Copy that formula to Cell C2.
Results:
The INDIRECT uses the text in the column headings to point to a valid range reference. This is just illustration. You wouldn't likely use a mixture of named ranges and text ranges, and its not very clean to write out, "Sheet1!A1:A4" but you can use any of the standard formula to arrive at a textual reference.
Try
Change the formula in B2:
"=SUM(INDIRECT("Sheet"&COLUMN()))&"!A1:A4"))"
Now copy that to cell C2.
Results
Well, are the same. The SUM from cells A1:A4 is being returned from Sheets 2 and 3 respectively. This time, however, the column headers are not being used, and the range reference is being assembled in the INDIRECT call itself using the string join "&" operator and the COLUMN number.
Named ranges can be used in the same way. What's important to understand is that anything inside the INDIRECT parenthesis needs to first be resolved to a vaild TEXT range reference.
I hope that helps!