IfError with else, does this function exist in Excel? - excel

While trying to help the author of this other question, I bumped (again) into the situation that I would like the following Excel function:
=IFERROR(value, value_if_error, value_if_no_error)
In other words, I'm looking for an IFERROR() function with an else-clause.
The issue is: it can in theory be done as follows:
=IF(IFERROR(function(),error_value),value_if_error,value_if_no_error)
But what if error_value is a possible outcome of function()? That would make it impossible to use IFERROR(): e.g. function() returns a string, which can be anything, also an empty string, but it might also generate an error.
Edit: some clarification
Let me give an example:
=IFERROR(B3, "weird")
In "B3", there is a function, which returns a string, but even in case the value of this string is "weird", this is ok. How can I distinguish the erroneous case and the case where "weird" is a normal correct result?
As an image says more than a thousand words:

Next to IFERROR(), there also is the ISERROR() function, which can be used as an input for an IF()-clause:
=IF(ISERROR(value),value_if_error,value_if_no_error)

Related

problem of syntax in function indirect hlookup

I did this function in excel, and it works perfectly :
=RECHERCHEH(H$3;INDIRECT("'"&parametre!$B$3&"["&parametre!$B$4&"]"&parametre!$B$5&"'!$1:$200");LIGNE();0)
But when I try to replace
$1:$200 per
=RECHERCHEH(H$3;INDIRECT("'"&parametre!$B$3&"["&parametre!$B$4&"]"&parametre!$B$5&"'!RECHERCHEV(C5;parametre!$B$7:$C$11;2)");LIGNE();0)
it doesn't work.
when I isolate my function rechercheV, I got it :
=RECHERCHEV(C5;parametre!$B$7:$C$11;2)
and it returns me :
AF:BE
So i try to put in my function rechercheV in my "big function" but no way to work for the moment
Can you help me pls ?
Thanks for reading me
The quotes around RECHERCHEV(C5;parametre!$B$7:$C$11;2) mean that exactly that text "RECHERCHEV(...." is being interpreted for the formula, not the value that the function would return.
Try this:
=RECHERCHEH(H$3;INDIRECT("'"&parametre!$B$3&"["&parametre!$B$4&"]"&parametre!$B$5&"'!"&RECHERCHEV(C5;parametre!$B$7:$C$11;2));LIGNE();0)

How to correct an Excel formula error

=O27&" "&IF(D27<>"",VLOOKUP(D27,성취기준1반!$B$4:$C$19,2)&" ","")&IF(E27<>"",VLOOKUP(E27,성취기준1반!$E$4:$F$19,2)&" ","")&IF(F27<>"",VLOOKUP(F27,성취기준1반!$H$4:$I$19,2)&" ","")&IF(G27<>"",VLOOKUP(G27,성취기준1반!$K$4:$L$19,2)&" ","")&IF(H27<>"",VLOOKUP(H27,성취기준1반!$N$4:$O$33,2)&" ","")&IF(I27<>"",VLOOKUP(I27,성취기준1반!$Q$4:$R$33,2)&" ","")&IF(J27<>"",VLOOKUP(J27,성취기준1반!$T$4:$U$33,2)&" ","")&IF(K27<>"",VLOOKUP(K27,성취기준1반!$W$4:$X$33,2)&" ","")&IF(L27<>"",VLOOKUP(L27,성취기준1반!$Z$4:$AA$33,2)&" ","")&IF(M27<>"",VLOOKUP(M27,성취기준1반!$AC$4:$AD$19,2)&" ","")&P27
this is working code
=O28&" "&IF(D28<>"",VLOOKUP(D28,성취기준1반!$B$4:$C$19,2)&" ","")&IF(E28<>"",VLOOKUP(E28,성취기준1반!$E$4:$F$19,2)&" ","")&IF(F28<>"",VLOOKUP(F28,성취기준1반!$H$4:$I$19,2)&" ","")&IF(G28<>"",VLOOKUP(G28,성취기준1반!$K$4:$L$19,2)&" ","")&IF(H28<>"",VLOOKUP(H28,성취기준1반!$N$4:$O$33,2)&" ","")&IF(I28<>"",VLOOKUP(I28,성취기준1반!$Q$4:$R$33,2)&" ","")&IF(J28<>"",VLOOKUP(J28,성취기준1반!$T$4:$U$33,2)&" ","")&IF(K28<>"",VLOOKUP(K28,성취기준1반!$W$4:$X$33,2)&" ","")&IF(L28<>"",VLOOKUP(L28,성취기준1반!$Z$4:$AA$33,2)&" ","")&IF(M28<>"",VLOOKUP(M28,성취기준1반!$AC$4:$AD$19,2)&" ","")&P28
this is doesn't workin code.
Why doesn't it work?
This is not an answer in terms of a solution, but an answer in terms of the method you could employ to find and solve the issue. Mainly because you have not provided a working verifiable example, data or detail of the actual error.
First I would remove the vlookups and replace them with the expected results - if that then functions as it should then each of the vlookups needs to be tested, if not then check the detail of the function.
Appreciate if you can assist by explaining.. "why this doesn't work?" part. It is an error message or the the expected value is _ but I got _ instead.. (:
One thing I noticed is that you don't define what will be the outcome if D28 is "". If you don't define it, it'll return 'FALSE' value instead of a String/text.
In your IF() function, you only say IF(d28<>"",<DisplayValueFrom성취기준1반>) it should be IF(d28<>"",<DisplayValueFrom성취기준1반>,<DisplaySomeThingElse>)

Excel Nested IF statements returning False

I am constructing a nested IF statement, and I believe I am missing an ELSE but I cannot figure out where. I have the following statement:
=
IF(AND(B2="4",E2="R37",X2="Y"), "Non-Competing",
IF(AND(B2="4",E2="R37",X2="N"), "Competing",
IF(AND(B2="4",E2<>"R37",RIGHT(Z2,2)="00"), "Non-Competing",
IF(AND(B2="4",E2<>"R37",RIGHT(Z2,2)<>"00"), "Competing",
IF(B2<>"4","-")))))
I thought the last bit would cover the rest, but I am receiving a FALSE when I was hoping to get a result. For example, when B2=4, E2=R37, and X2=Y, I am expecting "Non-Competing" but am receiving FALSE. I also tried a combination with OR:
IF(OR(AND(B41="4",E41="R37",X41="Y"),
AND(B41="4",E41<>"R37",RIGHT(Z41,2)="00")), "Non-Competing",
IF(OR(AND(B41="4",E41="R37",X41="N"), AND(B41="4",E41<>"R37",RIGHT(Z41,2)
<>"00")), "Competing",
IF(B41<>"4","-")))
...which gives me the same result.
Any assistance would be greatly appreciated!
The missing else is in IF(B2<>"4","-"). You need IF(B2<>"4","-",<whatever last-ditch-answer>) If you are reaching False, then B2 is 4, but none of the other full conditions were met.
Without seeing your data, I can't know for sure, but I'm guessing that you may have intended that entire statement to behave as an else. If that is case, I would replace IF(B2<>"4","-") directly with "-".

automating string and number concatenation

I'm having some trouble automating a matlab script which should prompt the user for the variable they are interested in, as well as the date range they want. I then want the script to concatenate their answers within a naming convention for the file they will ultimately load.
variable=input('please input variable of interest');
% temp
start=input('please state the start date in the form yymmdd: ');
%130418
enddate=input('please state the end date in the form yymmdd: ');
%140418
file=sprintf('%s_dailydata_%d_%d.csv',variable,start,enddate);
%so I thought 'file' would look like: temp_dailydata_130418_140418.csv
vardata=load(file);
the two numbers representing the dates are not causing any issues, but the fact that 'variable' is a string is. I know if I put apostrophes before and after 'temp' when I'm promted, it will work, but I have to assume that the end user won't know to do this. I tried putting curly braces around 'please input your variable..', but that didn't help either. Obviously this approach assumes that the date being requested exists in a filename.
Can anyone offer any advice? Perhaps the sprintf function is not the best option here?
Don't use 'end' as a variable name, it is a reserved name and using it could create conflicts with any function or logic block you're defining.
If you know your input is going to be a string: from the documentation for input()
str = input(prompt,'s')
Returns the entered text as a MATLAB string, without evaluating expressions.
As for knowing whether or not the file exists, that's something you'd have to incorporate some error logic for. Either a try/catch block with your load() call or you could use uigetfile() to get the filename.

Excel's Find function; Exceptions over values

I recently learned that Excel's Find function returns a #VALUE error when it doesn't find the needle in the haystack (i.e. no match is found). I have several questions about this behavior:
Is there another Excel function that works as Find but returns an actual value (e.g. -1) when no match is found?
Is there any well-known reason for the function having that behavior? I mean, talking about general programming and software design, Is there a known pattern (or methodology, or design philosophy) that prefers throwing exceptions over returning values (like -1, 0, "" or similar) when a function doesn't return a "valid" value?
The Find function looks for a case-sensitive match, and can be tested with IsNumber, like:
=IF(ISNUMBER(FIND("abc",A1)),FIND("abc",A1),"No exact match")
There is a very similar function called Search which does the same thing, but is not case sensitive. It also returns an error if no match is found.
So if you are looking for something and want to return -1 if there is no match and you are not worried about being case sensitive, then something like this should work for you:
=IF(COUNTIF(A1,"*abc*")=0,-1,SEARCH("abc",A1))
For case sensitive searches, it would be:
=IF(ISNUMBER(FIND("abc",A1)),FIND("abc",A1),-1)
If you are on Excel 2007 or later, you can skip the error checking by using IFERROR:
=IFERROR(SEARCH("abc",A1),-1)
=IFERROR(FIND("abc",A1),-1)

Resources