I use formula =SEARCH({"N.","No.","#"},D5) and it fails if doesn't fit first option "N." how can I fix it?
Using =SEARCH({"N.","No.","#"},D5) formula when you will see how the formula calculates the result using Evaluate Formula, you'll notice
evaluates to
That means formula is searching only for "N."
Therefore to search for the existence of "N.","No.","#" in a cell, number of approaches are available like:
1. =IF(COUNT(SEARCH({"N.","No.","#"},D5)),1,"")
This formula will give 1 if any of the string in the cell exists.
2. =SUMPRODUCT(--ISNUMBER(SEARCH(find_text,D5)))>0
This formula will give TRUE if any of the three string exists else FASLE.
Related
I'm running an excel formula and having issues with a #Spill error. The idea is that I have a column of cells that contain a ton of different numbers. I have another column with a bunch of String values that contain numbers as well.
For example,
Col A
Col B
1
String.10
2
String.1
3
String.3
4
String.6
The output, after running the formula, should return records of:
String.1
String.3
as 1 and 3 are contained in a cell.
The formula:
=IF(ISNUMBER(SEARCH($A$2:$A$10,B2)), "Yes", "No")
The idea is that I have a static range of cells to compare to and a way longer list of String.'numbers'. Why would this function result in a spill error?
Although this seems to be a trivial task, there are some pitfalls that need to be taken into account. For example, the problem that the search for "1" will be TRUE for both String.10 and String.1.
One approach to solving this issue in one formula could be as follows, combining, in particular, the following functions: TEXTJOIN(), BYROW(), and FILTER(). I also use some other functions that come in handy to find the exact string, etc.
Assuming that the data is stored in the range A2:B5, you can enter the following formula in C2, for example:
=TEXTJOIN(";",TRUE,
BYROW(A2:A5,LAMBDA(rowN,
FILTER($B$2:$B$5,
EXACT(rowN,RIGHT($B$2:$B$5,LEN($B$2:$B$5)-SEARCH(".",$B$2:$B$5)))=TRUE,""))))
The output of this formula looks as follows: String.1; String.3.
The TEXTJOIN() function combines the output of the BYROW() function separated by e.g, ";". In the BYROW() function, you first specify the array to which you want to apply the function specified in the LAMBDA()statement. In this context, rowN is then in the following simply used as the name for this particular array. The FILTER() function is used to filter data from a specified range that meets a certain criterion. The criterion in this context is that the number (specified in column A) matches the numeric part of the string in column B. To extract only the numeric part of the string, the number after the "." is extracted by combining the RIGHT(), LEN(), and SEARCH() functions. Subsequently, it is important to use the EXACT() function to ensure that when searching for "1", only this particular row is recognized as TRUE and not also the number "10", which also contains a 1.
Variation of the specification to get the output in a different format:
If you do not want the strings combined, you can simply delete the TEXTJOIN() function, which will return the corresponding string or an empty cell:
=BYROW(A2:A5,LAMBDA(rowN,FILTER($B$2:$B$5,EXACT(rowN,RIGHT($B$2:$B$5,LEN($B$2:$B$5)-SEARCH(".",$B$2:$B$5)))=TRUE,"")))
If you want to return "Yes" or "No", you can put the formula into an additional IF() statement as follows:
=IF(BYROW(A2:A5,LAMBDA(rowN,FILTER($B$2:$B$5,EXACT(rowN,RIGHT($B$2:$B$5,LEN($B$2:$B$5)-SEARCH(".",$B$2:$B$5)))=TRUE,"")))<>"","Yes","No")
In addition, I give some flavor for the spill error. This occurs because you are looking for a specific string in an array of values. Therefore, the output returns "Yes" and "No" for each row. In your particular case (the formula you presented above), an array containing 9 times "Yes" or "No" will be returned. Thus, if you then copy the formula down, you will get the spill error because you have stored something in the row and it is not possible to spill the 9 values down.
=BYROW($B$2:$B$5,LAMBDA(B,ISNUMBER(XMATCH(--(INDEX(TEXTSPLIT(B,".",,),2)),$A$2:$A$10))))
This will spill results (TRUE/FALSE) for all values.
It splits the text in column B and shows the string after the .. It's then converted from text to number by using --() and that value is matched with the values in column A. If it matches it returns the row number, so ISNUMBER is TRUE.
If no match is found, it throws an error, which is not a number, so ISNUMBER is FALSE.
Using LET will make it easier to update the ranges Col_A and/or Col_B. (You may even want to use a FILTER for Col_B: Col_B,DROP(FILTER(B:B,B:B<>""),1)) :
=LET(
Col_A,A2:A10,
Col_B,B2:B5,
BYROW(Col_B,LAMBDA(B,
ISNUMBER(
XMATCH(--(INDEX(TEXTSPLIT(B,".",,),2)),
Col_A)))))
When I run VLOOKUP Formula for 'E' it doesn't find the appropriate value. But all the other formulas gives the correct value as shown in the picture. Can someone help me with this please?
You don't specify a 4th argument in your VLOOKUP function, in which case it defaults to TRUE and expects a lookup range sorted ascending (which you don't have)
Fix by adding a 4th argument of FALSE or 0, e.g. This formula in K2 copied down
=VLOOKUP(J2,M$2:N$7,2,FALSE)
Another option would be to sort your table based on the first column.....but that will also mean you will get an "approximate match" which might not be appropriate in this case, e.g. if you make J2 = "X" then with an approximate match the VLOOKUP will return "WEST"
See excel help on VLOOKUP for parameter explanations
Try copying M3 and pasting values (Alt E-S-V) in J4 and J10.
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)
I'm trying to use an INDEX MATCH function to automate filling one spreadsheet using data from another. However, the sheet I am filling has people's names listed in two separate cells (e.g. "John" in A1, "Doe" in B1), while the sheet I am filling from has them listed as "DOE, JOHN Q." in one cell. A regular INDEX MATCH function would never give a result since no cell in the domain contains just the string "Doe." Is there any way to perform the function for cells that have the lookup value within the cell as a substring?
For reference, this is my attempt at this problem, which of course returns an error:
=INDEX(Sheet2!G2:Sheet2!G2340,MATCH(B3,ISNUMBER(SEARCH(B3,Sheet2!C2:Sheet2!C2340)),0))
I think you're on the right track. I think your initial formula should work but you need to make two changes:
Match criteria should be "TRUE" instead of "B3", as the result iof the ISNUMBER() function is a TRUE or FALSE
When entering the formula, press CTRL+SHIFT+ENTER instead of just ENTER, to make this an array function
Formula:
=INDEX(Sheet2!G2:Sheet2!G2340,MATCH(TRUE,ISNUMBER(SEARCH(B3,Sheet2!C2:Sheet2!C2340)),0))
If you wanted to search for both the first and last name, you could multiply two ISNUMBER() arrays together, and search for 1 instead of TRUE. This would get it to match both A3 and B3:
=INDEX(Sheet2!G2:Sheet2!G2340,MATCH(1,ISNUMBER(SEARCH(A3,Sheet2!C2:Sheet2!C2340))*ISNUMBER(SEARCH(B3,Sheet2!C2:Sheet2!C2340)),0))
Alternately, you could attempt to match both first and last names together with:
=INDEX(Sheet2!G2:Sheet2!G2340,MATCH(TRUE,ISNUMBER(SEARCH(B3&", "&A3,Sheet2!C2:Sheet2!C2340)),0))
Hope this helps. If I missed something, let me know!
You may concatenate the strings and provide that as an argument for MATCH or INDEX function. Still it would not work precisely as you do not have second names/initials like
MATCH(B1 & ", "& A1, Sheet2!C2:C2340, -1)
Although, you need to provide more details to get anything more from the StackOverflow community.
In Excel we have the VLOOKUP function that looks for a value in a column in a table and then returns a value from a given column in that table if it finds something. If it doesn't, it produces an error.
Is there a function that just returns true or false depending on if the value was found in a column or not?
You could wrap your VLOOKUP() in an IFERROR()
Edit: before Excel 2007, use =IF(ISERROR()...)
You still have to wrap it in an ISERROR, but you could use MATCH() instead of VLOOKUP():
Returns the relative position of an
item in an array that matches a
specified value in a specified order.
Use MATCH instead of one of the LOOKUP
functions when you need the position
of an item in a range instead of the
item itself.
Here's a complete example, assuming you're looking for the word "key" in a range of cells:
=IF(ISERROR(MATCH("key",A5:A16,FALSE)),"missing","found")
The FALSE is necessary to force an exact match, otherwise it will look for the closest value.
Just use a COUNTIF ! Much faster to write and calculate than the other suggestions.
EDIT:
Say you cell A1 should be 1 if the value of B1 is found in column C and otherwise it should be 2. How would you do that?
I would say if the value of B1 is found in column C, then A1 will be positive, otherwise it will be 0. Thats easily done with formula: =COUNTIF($C$1:$C$15,B1), which means: count the cells in range C1:C15 which are equal to B1.
You can combine COUNTIF with VLOOKUP and IF, and that's MUCH faster than using 2 lookups + ISNA. IF(COUNTIF(..)>0,LOOKUP(..),"Not found")
A bit of Googling will bring you tons of examples.
We've always used an
if(iserror(vlookup,"n/a",vlookup))
Excel 2007 introduced IfError which allows you to do the vlookup and add output in case of error, but that doesn't help you with 2003...
You can use:
=IF(ISERROR(VLOOKUP(lookup value,table array,column no,FALSE)),"FALSE","TRUE")
ISNA is the best function to use. I just did. I wanted all cells whose value was NOT in an array to conditionally format to a certain color.
=ISNA(VLOOKUP($A2,Sheet1!$A:$D,2,FALSE))