I am using an INDIRECT function to get value of a cell (B4) for many sheets in my workbook.
At the moment I have to hard code the name of the sheets like this
=INDIRECT("WCNEXP!$B$4")
Ideally I would like to find a way to compile the name "WCNEXP" with the help of the CONCATENATE formula, like this
=INDIRECT("CONCATENATE(B18,C18)!$B$4")
but it does not work for some reason.
Is there another way to get the name compiled from 2 cells and use the INDIRECT Formula ?
Photo of the workbook
Your code is almost good.
the quotes must be placed after the concatenate function, and with the use of "&" to join them.
=INDIRECT(CONCATENATE(B18,C18)&"!$B$4")
Related
I have a matrix grid in "MasterSheetGrid". I have separate sheets that divide this info into certain dimensions, making it easier to handle for the user.
In order to make the file dynamic, i am trying to use INDIRECT Function within a function, to locate which row of the MasterSheetGrid to look for the information before returning.
The formula works when i specify the row manually, but using INDIRECT i receive a REF error, even though nothing is deleted.
Manual Formula =INDEX(MasterSheetGrid!$5:$5,MATCH((XLOOKUP($J6,$5:$5,6:6)),MasterSheetGrid!6:6,0))
Formula to locate the row
=(MATCH($C6,MasterSheetGrid!$C:$C,0))
Attempt to merge both using INDIRECT by referencing the cell where the above formula is stored, which results in REF
INDEX(MasterSheetGrid!$5:$5,MATCH((XLOOKUP($J6,$5:$5,6:6)),(INDIRECT(J2:J2,0))))
Ideally i would like to not have to use a cell to store the lookup row formula in, but i thought if i could create a correct formula with the cell reference, i could repeat for the formula.
Does anyone know what i am doing wrong?
This is the view of the user. The formula would sit within column K
This is the MasterSheetGrid view
Instead of using INDIRECT which would cause recalculation at any change in the file, I recommend using INDEX instead. You refer to a fixed sheet name, therefore no need to use INDIRECT.
=INDEX(MasterSheetGrid!$5:$5,MATCH((XLOOKUP($J6,$5:$5,6:6)),INDEX(MasterSheetGrid!$1:$50,J2,),0))
Would be the equivalent of what you tried.
Proper use of INDIRECT would be:
=INDEX(MasterSheetGrid!$5:$5,MATCH((XLOOKUP($J6,$5:$5,6:6)),INDIRECT("MasterSheetGrid!"&J2&":"&J2),0))
And it's good practice to take the following into account (thanks David Leal):
If the Sheet name you're referring to contains one or more spaces you need to wrap the name in ' like 'Sheet name'!
To refer a range using INDIRECT you can use the following syntax (as a string delimited, for example delimited by "):
=INDIRECT("J2:J10")
for a cell, this works:
=INDIRECT(J2)
but if you try the same for a range:
=INDIRECT(J2:J10) -> #REF!
you get #REF!
If you are going to refer a Sheet from your Worksheet, then you need in all cases to enter the input argument as string:
=INDIRECT("Sheet1!A1:A10")
=INDIRECT("Sheet1!A1")
=INDIRECT("'Sheet 1'!A2") -> When Sheet Name has spaces use (') delimiter
Notes: By the way you are invoking INDIRECT using the second input argument (a1) which is optional with the value 0. It is not required for getting a referring a range as I showed before.
I suspect this is the issue you are having
I'm trying to make a SUMIF function like this one
=SUMIF(OUT!$G$22:$G$70;'2018'!$B4;OUT!$J$22:$J$70)
But i would like instead of giving the name of the sheet OUT, i want the excel to read de name of the sheet from an other cell like i show on the img.
I tried =SUMIF(CELL("contents";E2)!$G$22:$G$70;'2018'!$B4;CELL("contents";E2)!$J$22:$J$70)
but still not working. Anyone knows how to do it?
Excel image
You need INDIRECT:
=SUMIF(INDIRECT("'"&E2&"'!G22:G70");'2018'!$B4;INDIRECT("'"&E2&"'!J22:J70"))
Note that since the ranges are literal text strings, you don't need to make them absolute since they won't adjust if you copy/fill anyway.
I want to create a summary file where I wish to import the data from cell D11 from some workbooks. For this I try to use INDIRECT to call the workbook O284, where O284 through O296 consists of strings like:
2015-01 (for O284), 2015-02 (for O285 etc)
and where O285 is the sheetname, which is consistent for each workbook hence the $$'s.
=INDIRECT("'C:\Path\["&O284&"]"&$O$285&"'!$D$11")
Running this however does not return a value, but merely a ####. I have all the workbooks opened. I suspect I conduct the INDIRECT snippet wrong, but I can't figure out how. Does anybody have a clue?
Regards,
Btw, is there a way to achieve the same thing as with INDIRECT that work with closed workbooks without using macros? Like a "paste value" or something which you can use in the same way as INDIRECT but that returns a digit, without the formula notation in the cell?
EDIT:
=INDIRECT(CONCATENATE("'C:\path\[";O282;"]";$O$283;"'!D11"))
works for getting the value "D11" from the workbook O282. When I drag this formula out, the next column will reference to workbook P282. However, it still get cell D11. I want it to get the E11 cell from this workbook, and work like this. Does anyone have any idea?
=INDIRECT(CONCATENATE("'C:\";[#Path];"\[";[#WorkbookName];"]";[#SheetName];"'!";ADDRESS(11;COLUMN() - 11)))
I think up code is something that can you want.
Showing #### is sometimes because of cell width.
I'm making multiple IF statements that are going to have the same layout. Instead of writing the reference sheet name I'd like to reference a cell for the sheet name.
Also in the interests of laziness I'd like to drag the formula so it changes locations it is looking at on the referenced sheet.
At the moment it looks like this.
=IF(sheet1!O2="","",sheet1!O2)
Simple enough.
However I want to use indirect and I can't write it without getting an error.
Last attempt was
=IF((indirect($B$3))!O2="","",(indirect($B$3))!O2)
where Sheet1 is in the cell B3
Doesn't work.
Any help on the correct syntax would be very appreciated.
You need to concatenate $B$3 and "!O2" to generate "Sheet1!O2" as a string for INDIRECT to work, as below:
=IF(indirect($B$3&"!O2")="","",indirect($B$3&"!O2")
Alright, I am trying to figure out if the following is possible so that I can use it in later projects. I have been testing and working on this code in a sample workbook, which is why the file name is garbage. So don't judge me.
I have a VLOOKUP:
=VLOOKUP(A6,[dfhdfh.xlsx]Sheet1!$A:$B,2,FALSE)
This function currently works great. But I want to replace the static table_array value in the function to a cell reference, where I can enter a different file name at will.
Something along the lines of:
=VLOOKUP(A3,CONCATENATE("[",F2,"]","Sheet1!$A:$B"),2,FALSE)
Where F2 contains the file name and extension dfhdfh.xlsx
But whenever I try to execute my VLOOKUP with it's nested CONCATENATE function, I get a #VALUE! error. What gives?
Follow up from comments
If your workbook dfhdfh.xlsx is always open, you can use
=VLOOKUP(A3,INDIRECT("["&F2&"]Sheet1!$A:$B"),2,0).
But if your wb is closed, INDIRECT doesn't work. In that case you need VBA solution.
About your formula:
1) CONCATENATE(A1,A2) is the same as A1 & A2.
2) Actually concatenation works and result of CONCATENATE("[",F2,"]","Sheet1!$A:$B") would be "[dfhdfh.xlsx]Sheet1!$A:$B", but excel doesn't recognize this string as reference.
So you need to use Indirect for this purpose:
INDIRECT(CONCATENATE("[",F2,"]","Sheet1!$A:$B")) gives you correct reference.
Entire formula would be:
=VLOOKUP(A3,INDIRECT(CONCATENATE("[",F2,"]","Sheet1!$A:$B")),2,FALSE).
But, using first point, you can make this formula shorter:
=VLOOKUP(A3,INDIRECT("[" & F2 & "]Sheet1!$A:$B"),2,FALSE)