Why am I getting a value error in excel while using the ifs function? - excel

=IFS(SEARCH("C*",A9),"Cake",SEARCH("K*",A9),"Cookies",SEARCH("B*",A9),"Bread & Bun",SEARCH("Y*",A9),"Pastry")
It works for the first criteria and returns "cake" but won't work for the others. I keep getting a #VALUE error.
Can help please??

SEARCH isn't a Boolean-valued function. It doesn't return FALSE if the string isn't found -- it returns a #VALUE! error which isn't coerced to FALSE.
What you could do is wrap everything like SEARCH("C*",A9) with ISNUMBER(): ISNUMBER(SEARCH("C*",A9)) since Excel can tell that #VALUE! isn't a number.

Related

Why does this report #Value error in Excel

Just trying to report binary test...
=IF(FIND("RHS",B14),"RHS","LHS")
The function works for RHS, but reports #value for LHS. Why?
The FIND function returns the index of a string within another string, however, if the string you are looking for is not there it results in an error and displays "#value".
Likewise the if function is expecting an expression that results in a true or false value like: if ( this expression =true, then do this , otherwise do this)
Since the find function returns an error #value, it causes the if statement to also error out, when trying to calculate what to do.
To mitigate this you can wrap the function with either an ISNUMBER OR ISERROR function to validate if the find function is indeed returning an expected result
=IF(ISNUMBER(FIND("RHS",B14)),"RHS","LHS")
=IF(ISERROR(FIND("RHS",B14)),"LHS","RHS")
If expects a boolean result.
Find returns i9f it finds sowethig a number if Not showws an error that is why RDS works
A ISNUMBER returns suich a boolean result, that is needed
=IF(ISNUMBER(FIND("RHS",B14)),"RHS","LHS")

WorksheetFunction.value() missing in Excel

In a spreadsheet formula, =VALUE("$100") will evaluate to the numeric value of 100. I then tried to access this function in VBA via WorksheetFunction object, however it is missing.
In VBA I tried the conversion function Val("$100"), however that returns 0. So how can I accomplish this via VBA?
Val() only really works if the string is all numbers I'm afraid - currency signs cause it a problem.
If you're always going to have the same currency sign in the string, it might be worth using something like
StringName = replace(StringName, "$", "")
to take out the $ by replacing it with "" - otherwise if your strings aren't always going to be this predictable the below question might help:
How to find numbers from a string?
see https://learn.microsoft.com/en-us/office/vba/api/excel.worksheetfunction.numbervalue
example of using above, which will return a value of -1234.56:
MsgBox WorksheetFunction.NumberValue("-$1,234.56", ".", ",")
Note that if the result is non-numeric, it throws an error. For example (swapping the comma grouping and decimal character params which is invalid in this case):
MsgBox WorksheetFunction.NumberValue("-$1,234.56", ".", ",")
I don't understand why the above link doesn't have any version info. It is currently dated 2019‎-‎05‎-‎23 - no idea if that's because it is new or if it was recently updated.

How can I nest an vector index match function in an if statement? (Excel)

I have the following vector function:
{=INDEX(Key!$K$2:$K$25,MATCH(TRUE,ISNUMBER(SEARCH(Key!$K$2:$K$25,V5)),0))}
This function returns what is in Key!$K$2:$K$25 if V5 is a match. This formula works. I would like to also make the function return, "Not Found", if the value searched for is not present in Key!$K$2:$K$25. I have tried the following, but it doesn't work. Could someone help?
{=IF(MATCH(TRUE,ISNUMBER(SEARCH(Key!$K$2:$K$25,V3)),0),INDEX(Key!$K$2:$K$25,MATCH(TRUE,ISNUMBER(SEARCH(Key!$K$2:$K$25,V3)),0)),"Not Found")}
Thanks.
simply merge your =INDEX(Key!$K$2:$K$25,MATCH(TRUE,ISNUMBER(SEARCH(Key!$K$2:$K$25,V5)),0)) with IFERROR
=IFERROR(INDEX(Key!$K$2:$K$25,MATCH(TRUE,ISNUMBER(SEARCH(Key!$K$2:$K$25,V5)),0)),"Not found")

IF, OR and IFERROR function in excel

Column_A Column_B New (Expecting result for this situation)
#N/A #N/A Manual Posting
My function has problem for the last syntax"IFERROR(IFERROR(....)" . Currently, I get #N/A for the "New" column. However, I want to get "Manual Posting" instead.
My syntax:
=IF(OR(IFERROR(B1,A1)="Bank BPH",IFERROR(B1,A1)="GE Budapest Bank"),"GECapital",IF(IFERROR(B1,A1)="Avio Aero","GE Aviation",IFERROR(IFERROR(B1,A1),"Manual Posting")))
Ok, working it out I think I can explain.
IFERROR(x,y) returns value x, unless it's an error, then it returns y .. (even if it is an error).
You then take result of that, and compare it to a string:
IFERROR(A1,B1)="Bank BPH"
Assuming valid values, that expression will, of course, return TRUE or FALSE.
If both A1 and B1 are error, however, what happens ??
What is the result of:
#ERR="string" ??
answer: an error ...
so what does the IF do with an error? it's neither true, nor false.
You can simplify the situation to just this expression to see what's going on:
=IFERROR(A1,B1)="Bank BPH"
it returns an error.
Neither true nor false.
You're going to need another check condition for an error and how to handle it ..
perhaps:
=IF(AND(ISERROR(A1),ISERROR(B1)), "Manual post", IFERROR(A1,B1)="Bank BPH")
might do the trick ??
I think I figure out the correct syntax. I used to put the "AND(ISERROR(B18),ISERROR(A18)),"Manual Posting" to the end. However, I moved it at the beginning, it seems the problem can be solved.
=IF(AND(ISERROR(B18),ISERROR(A18)),"Manual Posting",IF(OR(IFERROR(B18,A18)="Bank BPH",IFERROR(B18,A18)="GE Budapest Bank"),"GE Capital",IF(IFERROR(B18,A18)="Avio Aero","GE Aviation",IFERROR(B18,A18))))

How do I sum results of two if statements in the same cell?

I'm looking to have the results of two If statements calculated and added in the same cell. I'm getting #VALUE! error.
=IF(ISERROR(GETPIVOTDATA("Sum of CHARGES",'Ship City'!$A$3,"ship_city",$B$7,"carrier_type",$A$27,"INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29)),"",GETPIVOTDATA("Sum of CHARGES",'Ship City'!$A$3,"ship_city",$B$7,"carrier_type",$A$27,"INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29))+IF(ISERROR(GETPIVOTDATA("Sum of CHARGES",'Recipient City'!$A$4,"recipient_city",$B$7,"carrier_type",$A$27,"INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29)),"",GETPIVOTDATA("Sum of CHARGES",'Recipient City'!$A$4,"recipient_city",$B$7,"carrier_type",$A$27,"INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29))
=IF(ISERROR(GETPIVOTDATA("Sum of CHARGES",'Ship City'!$A$3,"ship_city",$B$7,"carrier_type",$A$27,"INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29)),"",GETPIVOTDATA("Sum of CHARGES",'Ship City'!$A$3,"ship_city",$B$7,"carrier_type",$A$27,"INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29))
+
IF(ISERROR(GETPIVOTDATA("Sum of CHARGES",'Recipient City'!$A$4,"recipient_city",$B$7,"carrier_type",$A$27,"INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29)),"",GETPIVOTDATA("Sum of CHARGES",'Recipient City'!$A$4,"recipient_city",$B$7,"carrier_type",$A$27,"INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29))
Your both IF functions return an empty string "". Using + operator with strings returns #VALUE!. There are different methods to fix it:
use 0 instead of ""
use SUM instead of + (it ignores strings).
And as #John Bustos mentioned in his comment, you can simplify your formula with
IFERROR(value,value_if_error)
IFERROR description

Resources