I don't have a decent way of explaining this but I'm going to try. Sorry.
I have two documents. I'm linking one document to the other to present some info from that first document into the second one inside a specific cell.
Let's say I want the data from B2 from my first sheet. Is the only way to do this is by typing B2 into the formula itself or can I create a variable and have that space be filled in by putting the appropriate cell number into another cell? If I want it to reference B2 from the external sheet, can I type B2 into a specific cell on the page and that cell is defined as my_number and I can place that variable my_number into the importrange formula?
Or can I not mix external and internal referencing? I tried to search for something similar online but I didn't have a lot of luck.
If this is still not explained very well, this is kind of a visual:
=IMPORTRANGE("mydocsheet.com/spreadsheet", "Sheet1![my_number]") instead of
=IMPORTRANGE("mydocsheet.com/spreadsheet", "Sheet1!B2")
Those are quoted strings representing cell range references; not true cell range references. You should have no problem using concatenated strings. With B2 in a named cell called my_number,
=IMPORTRANGE("mydocsheet.com/spreadsheet", "Sheet1!" & Sheet1!my_number")
Related
I am trying to achieve two things which I presume are possible but I'm unsure of where to start.
What I am hoping to achieve is to populate the list (shown in cell C4) with the data entered in cell A3. What I don't know is how to make the A3 string breakdown based on the comma delimiter so that it is not one long string, but rather results in a list at C4, as displayed in the screenshot.
Note: I have hardcoded the list shown in the screenshot as I wanted to show what I need to achieve. If I reference A3 directly (=$A$3), my list only has one item - 'Yes, No, I don't know', opposed to the list displayed in the screenshot.
Then, if this is possible, instead of hard coding A3 as the reference, I want to read the value in B4. This would allow me to change the value of B4 to point at any other cell, such as A6.
I believe both these things are likely possible but Googling has not helped as it appears I'm searching for the wrong keywords.
Instead of having all options in one cell, why don't you just make a list across different columns and then enter in the reference cell the letter of the column. Then in your validation, use indirect(cell ref & "1:" & cell ref & "Max row num").
Or better yet, name the ranges, then simply list the name of the range in the reference cell and use indirect(cell ref) to dynamically change drop down options. E.g your range would be named "fruit", in b4 you would enter "fruit".
May be you can try to separate them in cell A3
=SUBSTITUTE(LEFT($A$2,FIND(",",$A$2,1)),",","")
and try to paste as will in Cell A4
=MID(A2,FIND("Yes",$A$2,2),3)
so as will separate the last word to cell A5
=RIGHT(A2,LEN(A2)-FIND("Yes, ",$A$2)-4)
And your Source in your data validation would be
=$A$2:$A$4
I am using in Excel the following formula that works to get the value of a cell:
=INDEX(Sheet1!$1:$1048576,MATCH("Component 1",Sheet1!$A:$A,0)+MATCH("Component 2",Sheet2!$B:$B,0),2)
For a new application, the sheet and component names are dynamic, meaning that they are allowed to change and are not necessarily "Sheet1", "Sheet2", "Component 1" and "Component 2". Therefore I have tried to twist the above formula using the build-in INDIRECT function. I have tried two different ways to make it work:
1-
=INDEX(INDIRECT(A1&"!$1:$1048576"),INDIRECT("MATCH("&CHAR(34)&B1&CHAR(34)&","&A1&"!$A:$A,0)+MATCH("&CHAR(34)&B2&CHAR(34)&","&A2&"!$B:$B,0)"),2)
2-
=INDIRECT("INDEX("&A1&"!$1:$1048576,MATCH("&CHAR(34)&B1&CHAR(34)&","&A1&"!$A:$A,0)+MATCH("&CHAR(34)&B2&CHAR(34)&","&A2&"!$B:$B,0),2)")
where cells A1 and A2 values are the sheets' names and cells B1 and B2 receive the components' names.
Both approaches gives an error #Ref!. But I really cannot see what is wrong.
I would really appreciate any information for me to understand my mistakes and any suggestions to improve these formulas.
Thanks in advance!
Reason
You are using INDIRECT to compile parts of your formula, including the function names (e.g. "MATCH" in your "1-").
Instead, only use INDIRECT to build the actual references to ranges or cells (including qualifiers such as worksheet, workbook etc) inside those functions within your formula. Leave the rest of the formula outside the INDIRECT function.
So in your "1-", move "MATCH" back outside the "INDIRECT" function.
To get the "Component 1" to be volatile, just reference a cell containing that string in the normal way.
In your attempt "2-", you tried putting more of the formula inside the INDIRECT function, but it should have been less.
Answer
For example, you could try:
=INDEX(INDIRECT($A$1&"!$1:$1048576"),MATCH($B$1,INDIRECT($A$1&"!$A:$A"),0)+MATCH($B$2,INDIRECT($A$2&"!$B:$B"),0),2)
Even better
The difficulty is arising in part due to putting the sheet name in a range and the range reference hard coded in the formula.
You could consider putting "Sheet1!$1:$1048576" into A1 (for example), instead of just "Sheet1", and adjust formula accordingly. That way you can just edit A1, B1, B2 if the ranges change or grow, rather than editing the formula. Note that you would not be able to reuse A1 for the reference to "Sheet1!$A:$A", you would need a different cell to store that reference.
Also consider naming the cells A1, A2, B1 & B2, and referring to the named ranges in your lookup formula. That way if you move those cells around in certain ways it will be less prone to breaking your lookup formula.
Further thoughts
I presume you are across the performance tradeoffs of using volatile functions such as INDIRECT. If not, happy searching!
I have a spreadsheet full of references, pretty much every permutation you can imagine.
EX:
='January Scorecard'!F7
='February Scorecard'!F7
='March Scorecard'!H7
='April Scorecard'!H7
I want to be able to change specific things of the formula across an entire row or column. So if I need to change a row where all of the references currently point to 'H7', I want to be able to quickly change all of them to 'F31' or another arbitrary cell value.
What are quick ways to change cells specifically while keeping the reference sheets the same?
You need to use the INDIRECT function. This takes a cell reference which contains text representing a cell address, and converts it into that cell address. So if cell A1 had the text "H7", then your example cells would now have
=INDIRECT("'March Scorecard'!" & A1)
whcih would firstly convert to "'March Scorecard'!H7 " and then the indirect would convert it to ='March Scorecard'!H7
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!