I have a very seriously weird problems with Excel formula. Refer the following formula:
=INDEX(C7:D9, MATCH(H2, B7:B9, 0), MATCH(H3, C6:D6, 0))
Please assume the H2 and H3 is linked from some other formula which yield the value from B7:B9 and C6:D6 respectively. My problem is that the result is #N/A instead of returning value from the INDEX ARRAY.
The main problem is, that we don't know what H2:H3 returns
Taking your formula:
=INDEX(C7:D9, MATCH(H2, B7:B9, 0), MATCH(H3, C6:D6, 0))
H2 needs an output like Below 42°!
if there is only a number like 53 replace MATCH(H2, B7:B9, 0) with something like 1+(H2>=42)+(H2>58). However, if you got 53° you also need to replace H2 with something like NUMBERVALUE(LEFT(H2,LEN(H2)-1))
Same goes for H3: You need to get a return like "< 25". Asuming you only get a number, you need to replace MATCH(H3, C6:D6, 0) with something like 1+(H3>=25).
At least, it's not clear if thats the real problem. We really need to know the return values from H2 and H3.
You get #N/A because the MATCH-function fails. I'm almost certain it fails because the content of H2 is not type compatible with the contents in B7:B9 (or H3 not compatible with C6:D6).
Since you have string-type in B7:B9, H2 must also be string-type and the string must identically match one of the strings in B7:B9. If it matches none of them it throws #N/A.
If MATCH is unsuccessful in finding a match, it returns the #N/A error
value.
https://support.office.com/en-us/article/MATCH-function-e8dffd45-c762-47d6-bf89-533f4a37673a
If there is a type-mismatch, the function will automatically fail unless Excel can cast it to the right type on the fly (and understands that it is supposed to do that), because failure to complete the comparison naturally defaults to "no match" ~~> #N/A.
Examine the datatypes you are comparing and fix the discrepancies, and your formula will work.
Sorry guys for being unclear in my post. Well I finally fixed the problem by replacing "1" instead of "0" on my MATCH functions. I don't know why but it fixes the #N/A error.
Related
I was trying to make simple check of vlookup:
=IF(ISERROR(VLOOKUP(B2;SA!C:K;2;FALSE));"Error";VLOOKUP(B2;SA!C:K;2;FALSE))
Issue is that i got two different results for two empty cells.
Error
and
0
All cells are with the same type: General. Do not see why this is different :/
I was expecting message in case of iserror = TRUE (cell is empty). This case "Error".
Sample file: https://www.dropbox.com/s/jzoq9530qxtig38/ZZZ.xlsm?dl=0.
In C2 use the following formula:
=IFERROR(IF(LEN(INDEX(SA!$D:$K,MATCH($B2,SA!$C:$C,0),COLUMN(A1)))=0,"error",INDEX(SA!$D:$K,MATCH($B2,SA!$C:$C,0),COLUMN(A1))),"error")
Edit, since you don't really want to show "error" but "" instead, you could also try:
=IFERROR(INDEX(SA!$D:$K,MATCH($B2,SA!$C:$C,0),COLUMN(A1))&""),"error")
You are getting 0 because VLOOKUP found key, however the value next to it was empty.
To mark those as Error as well use:
=IF(LEN(IFERROR(VLOOKUP(B2;SA!C:K;2;FALSE);"Error"))=0;"Error";IFERROR(VLOOKUP(B2;SA!C:K;2;FALSE);"Error"))
I'm developing a financial model and as a completeness check, I need to provide the user with a completeness check that essentially ensures that a range of data does not have any #N/A errors. For example, I'd like the equation in J1 to return "Incomplete" if a single cell in the range A1:A80 has an #N/A value and "Complete" if not a single cell has an error. Any ideas?
Try the following
=COUNTIF(A1:A80,"#N/A")
So
=IF(COUNTIF(A1:A80,"#N/A")>0,"incomplete","Complete")
Though sounds like you want something more broad like:
=IF(SUMPRODUCT(--(ISERROR(A1:A80)))>0,"Incomplete","Complete")
For dynamic range try:
=IF(SUMPRODUCT(--(ISERROR(OFFSET(A1,0,0,COUNTA(A:A),1))))>0,"Incomplete","Complete")
To count #N/A's specifically you can always use something like:
=COUNTIF(A1:A80,VLOOKUP(,,,))
EDIT#1:
This formula relies on a tiny trick, you see this formula:
=VLOOKUP(,,,)
returns a #N/A. We deliberately create an error to count a specific type of error. Another example:
=COUNTIF(A1:A80,0/0)
will count cells with #DIV/0! in them.
(It is equally easy to count cells containing #REF! or #VALUE!)
If you don't need a count, then array enter the formula =OR(ISNA(SomeRange)). Array Enter means type the formula in the formula bar, and push Ctrl Shift Enter
If you want it to return a message, use something like =IF(OR(ISNA(SomeRange)),"Complete", "Incomplete")
If you do need a count, then use =COUNTIF(SomeRange,NA())
I want to get a formula with COUNTIFS, like
=COUNTIF(A1:A3,"<>"&"")
such that when A1 = 2, A2 = "", A3 = empty, it returns 1.
Notes:
A2 contains an empty string, as the result of a formula. A3 is a blank cell, with no formulas in it.
The formula posted returns 2.
I tried using various numbers of double quotes. I always get 2.
I tried using &CHAR(34)&CHAR(34). I get 2.
The solution posted in How do I get countifs to select all non-blank cells in Excel? is what I tried, it returns 2 (not useful).
The formula would actually be =COUNTIFS(range1,cond1,range2,cond2), that is why I cannot use something like
=ROWS(A1:A3)-COUNTIF(A1:A3,"") or =ROWS(A1:A3)-COUNTBLANK(A1:A3) (see this).
range1 and range2 would come from expressions with INDIRECT, but that is probably not relevant.
I have worked it out with =SUMPRODUCT(--(expression1),--(ISNUMBER(A1:A3))), but I am specifically asking about the possibility of using COUNTIFS. Discrimination of number vs. text (e.g.) is not relevant at this point.
Blank vs. Empty string is the source of "troubles" (see, e.g., this).
Excel itself is somewhat ambiguous with respect to the definition of BLANK. In my example, ISBLANK(A2) returns FALSE, but COUNTBLANK(A2) returns 1.
I am not interested in a user Function.
Use a SUMPRODUCT function that counts the SIGN function of the LEN function of the cell contents.
As per your sample data, A1 has a value, A2 is a zero length string returned by a formula and A3 is truly blank.
The formula in C2 is,
=SUMPRODUCT(SIGN(LEN(A1:A3)))
I was having this exact problem, and I just found out about the "?*" wildcard which searches for any one or more characters, thus avoiding the empty string problem--genius! See Jonathan Gawrych's answer (posted right after the selected answer) here:
Excel Countif Not equal to string length of zero
Not sure if this works for the OP, since it looks like the value in A1 could need to be handled as a number not a string, but it might help anyone else who arrived here looking for a text-parsing solution.
Is using SUM instead of COUNTIFS an option? If so, I've found it to be much more flexible for filtering data sets. For example:
=SUM(IF(NOT(ISBLANK(A1:A3)),IF(NOT(ISTEXT(A1:A3)),1,0),0))
(entered as an array formula). IF(NOT(ISBLANK(x))... filters out non-blanks, then IF(NOT(ISTEXT(x))... filters out non-text. Whatever survives the filters is counted by summing 1. You can add as many filters as necessary. If you wanted to filter out only empty strings but include other text entries you could use a filter like
IF(ISTEXT(x),IF(LEN(x)>0,1,0),0)
Is there an in-built function to check if a cell contains a given character/substring?
It would mean you can apply textual functions like Left/Right/Mid on a conditional basis without throwing errors when delimiting characters are absent.
Try using this:
=ISNUMBER(SEARCH("Some Text", A3))
This will return TRUE if cell A3 contains Some Text.
The following formula determines if the text "CHECK" appears in cell C10. If it does not, the result is blank. If it does, the result is the work "CHECK".
=IF(ISERROR(FIND("CHECK",C10,1)),"","CHECK")
For those who would like to do this using a single function inside the IF statement, I use
=IF(COUNTIF(A1,"*TEXT*"),TrueValue,FalseValue)
to see if the substring TEXT is in cell A1
[NOTE: TEXT needs to have asterisks around it]
This formula seems more intuitive to me:
=SUBSTITUTE(A1,"SomeText","") <> A1
this returns TRUE if "SomeText" is contained within A1.
The IsNumber/Search and IsError/Find formulas mentioned in the other answers certainly do work, but I always find myself needing to look at the help or experimenting in Excel too often with those ones.
Check out the FIND() function in Excel.
Syntax:
FIND( substring, string, [start_position])
Returns #VALUE! if it doesn't find the substring.
It's an old question but I think it is still valid.
Since there is no CONTAINS function, why not declare it in VBA?
The code below uses the VBA Instr function, which looks for a substring in a string. It returns 0 when the string is not found.
Public Function CONTAINS(TextString As String, SubString As String) As Integer
CONTAINS = InStr(1, TextString, SubString)
End Function
I like Rink.Attendant.6 answer. I actually want to check for multiple strings and did it this way:
First the situation: Names that can be home builders or community names and I need to bucket the builders as one group. To do this I am looking for the word "builder" or "construction", etc. So -
=IF(OR(COUNTIF(A1,"*builder*"),COUNTIF(A1,"*builder*")),"Builder","Community")
This is an old question but a solution for those using Excel 2016 or newer is you can remove the need for nested if structures by using the new IFS( condition1, return1 [,condition2, return2] ...) conditional.
I have formatted it to make it visually clearer on how to use it for the case of this question:
=IFS(
ISERROR(SEARCH("String1",A1))=FALSE,"Something1",
ISERROR(SEARCH("String2",A1))=FALSE,"Something2",
ISERROR(SEARCH("String3",A1))=FALSE,"Something3"
)
Since SEARCH returns an error if a string is not found I wrapped it with an ISERROR(...)=FALSE to check for truth and then return the value wanted. It would be great if SEARCH returned 0 instead of an error for readability, but thats just how it works unfortunately.
Another note of importance is that IFS will return the match that it finds first and thus ordering is important. For example if my strings were Surf, Surfing, Surfs as String1,String2,String3 above and my cells string was Surfing it would match on the first term instead of the second because of the substring being Surf. Thus common denominators need to be last in the list. My IFS would need to be ordered Surfing, Surfs, Surf to work correctly (swapping Surfing and Surfs would also work in this simple example), but Surf would need to be last.
Why not simply
COUNTIF(A1,"*xyz*")
This searches for any appearence of "xyz" in cell A1.
It returns "1" when found, and "0" when not found.
Attention, the search is not case sensitive, so any of xyz, XYZ, XyZ, and so on will be found. It finds this as substrings in the cell, so also for abcxYz you get a hit.
If you do not want to write your search string into the formula itself, you can use
COUNTIF(A1,"*" & B1 & "*")
and enter your search string into B1. - Attention, when B1 is empty, the formula will return "found" ("1") as the search string is then read as "**".
Interesting *
=COUNT(MATCH("*SomeText*",A1,))
=COUNTA(VLOOKUP("*SomeText*",A1,1,))
=COUNTA(HLOOKUP("*SomeText*",A1,1,))
this returns 1 if "SomeText" is contained within A1.
Here is the formula I'm using
=IF( ISNUMBER(FIND(".",A1)), LEN(A1) - FIND(".",A1), 0 )
I have a formula that I am using in excel. The formula returns an array of values in the form of a column. I only know how to use an IF statement on a cell or a formula that returns one cell. However, I don't know how to apply it to get it to replace all the 0 values by NA() in the array returned by the formula. I want to wrap the formula using the IF statement.
It is a Reuters formula : =IF(RData(D17:D26;H16) = 0; NA(); RData(D17:D26;H16)), but it does not work at all.
RData(D17:D26;H16) returns the following column
H16 contains: AST_SWPSPD
D17:D26 contains the following RIC Codes:
BMPS2YEUAM=R
BMPS3YEUAM=R
BMPS4YEUAM=R
BMPS5YEUAM=R
BMPS7YEUAM=R
BMPS10YEUAM=R
BMPS20YEUAM=R
BMPS30YEUAM=R
The resulting column is the following
201.7
499.5
389.2
470.6
306.8
0
0
525.3
525.3
525.3
I want to get rid of the zeros and replace them with NA
Is that possible?
Thank you.
It should be exactly the same. Lets pretend your formula is F (but it would be much better if you added your actual formula or something similar to your question)
=IF(F=0, NA(), F)
Will work even if F is returning an array. Just replace F with your entire formula and don't forget to press ctrl+shift+enter
Thank you all for your input,
I found a way to go around it, simply by returning one value at a time and wrapping it with the IF statement.
So it becomes: =IF(RData(D17;$H$16)=0;NA(); RData(D17;$H$16))
I am fixing H16 because it contains the argument needed for the formula.
This way it works.
Instead of using =IF(RData(D17;$H$16)=0;NA(); RData(D17;$H$16)) you can also use =IFERROR(1/(1/(RData(D17;$H$16)));NA())
This way, your function gets only called once, which will reduce calculation time.