I am looking for a way to make an INDIRECT formula ignore errors and print a 0 instead. I have it working in a round about way but would like it neater.
I have an INDIRECT formula to load a cell from a seperate worksheet
=INDIRECT("'Invoice (2)'!A1")
The reason I've used an INDIRECT is so that when the sheet named 'Invoice (2)' is not available (i.e. I've temporarily deleted it) it does not change my formula.
However. When there is NO 'Invoice (2)' sheet, I get the error: #REF!
What I would prefer is the result to be '0'.
I have a work around by hiding this field and then referencing it in an AGGREGATE field
=AGGREGATE(9,6,N19) - The 6 ignores any errors and puts a '0' in place and this works perfectly.
So I guess I am just curious if there is a way to combine the two as to make it neater. You would think there would be an 'ignore error' for other commands other than aggregate.
I have tried =AGGREGATE(9,6,INDIRECT("'Invoice (2)'!A1")) and the script finds the data fine but it does not ignore errors like it should.
Wrap your formula with the IFERROR function thus:
=IFERROR(INDIRECT("'Invoice (2)'!A1"),0)
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 do the following.
Take a value in a defined cell
Look up that value on another sheet called 'Updates'.
Look across the row for the last non-empty cell
Look up from there and return the header.
I know that if there was a defined range, the following formula works great for the last two steps.
=LOOKUP(2,1/(Updates!B3:E3<>0),Updates!B2:E2)
However I tried to make it more flexible with INDIRECT and came up with the abomination of a formula which I intended to just copy down.
=LOOKUP(2,1/INDIRECT("Updates!B"&B5+2&":S"&B5+2<>0),Updates!$B$2:$S$2)
However this just returns a #REF error. Is this type of thing not possible or is there a simpler way to go about it?
Thanks
I think you're not closing the INDIRECT statement before making the <>0 test - so move that bracket to the left and it should work; ie
= LOOKUP(2,1/INDIRECT("Updates!B"&B5+2&":S"&B5+2) <>0, Updates!$B$2:$S$2)
So I've been trying to work with dynamic drop-down lists in data validation, and I've had a lot of success, but for some reason this particular formula is kicking my butt:
=IF(ISERROR(INDEX(INDIRECT(A2&"SL1"),1,1)),A1,INDIRECT(A2&"SL"&INDEX(LevelO, V2, MATCH(A2, LevelO[#Headers]))))
I've used all components of that before with no issues. However, the last INDEX is causing issues. If I remove that and hardcode the column number instead so it looks like this:
=IF(ISERROR(INDEX(INDIRECT(A2&"SL1"),1,1)),A1,INDIRECT(A2&"SL"&9))
Then it works fine. Why can't I use an INDEX function inside an INDIRECT function when it's fine the other way around? By the way, all of the applicable tables and ranges exist, that's not an issue. When I put the first formula into a cell it evaluates all of the named ranges just fine (using formula evaluation). This is with Excel 2007.
First you can create a name in the name manager in the *Formula Tab, and then give a name to your new name and put your formula in the refers to. Once done, you can use the same name in the data validation, instead of putting down your formula in the refers to box, insert the name you created.
It should work.
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")
=IF(ISBLANK(BLANK(CG3),"",(IF((LEFT(CG,2)="/m"),"mcat||"&CG3,"icat||"&CG3)))
I am getting a #NAME? error on the above formula.
CG3 contains either /mcat/... OR /icat/... currently. I need to add the prefix "mcat||" or "icat||" depending on the text currently there. Also, if CG3 is blank I want it to remain blank.
2 Issues:
Missing parenthesis in the ISBLANK function. (On second thoughts, this looks like a copy/paste issue.)
Missing cell number in the LEFT function.
Should be:
=IF(ISBLANK(CG3),"",IF(LEFT(CG3,2)="/m","mcat||"&CG3,"icat||"&CG3))