IF ISNUMBER SEARCH - distinguish between similar text - excel

Hoping someone smarter than myself can help:
Column F contains either of the words below, and I want to excel formula to return whether the data is "White" or "Pink"
Ban
Bandearg
=IF(ISNUMBER(SEARCH("Ban",F2)),"White",IF(ISNUMBER(SEARCH("Bandearg",F2)),"Pink")
The problem is that everything returns as "White" as it is finding "Ban" in both. Presume I am using the formula wrong.
Bán is the Irish for White and Bándearg is the Irish for Pink!

As per my comment, simply swap them around:
=IF(ISNUMBER(SEARCH("Bandearg",F2)),"Pink",IF(ISNUMBER(SEARCH("Ban",F2)),"White"))
ISNUMBER checks wheather or not SEARCH returns a number (meaning the substring is found starting at that index/position) or an #VALUE error. In the first case, it will return TRUE, otherwise FALSE continueing with the second nested IF. Note that this formula will return FALSE if "Ban" isn't found at all.

Maybe just simply add a space behind the criteria and the result value, and your formula become :
=IF(ISNUMBER(SEARCH("Ban ",F2&" ")),"White",IF(ISNUMBER(SEARCH("Bandearg ",F2&" ")),"Pink"))

If those words are all that the cell contains, you can simply use:
=IF(A1="Ban","White",IF(A1="Bandearg","Pink",""))
or, in later versions of Excel (2019+ or O365):
=IFS(A1="Ban","White",A1="Bandearg","Pink",TRUE,"")

Related

Excel customer data validation for chars and numbers

I am trying to validate a combination of char and numbers that looks like this XXXX0000000.
I have tried this formula; =OR((LEFT(B2,3)="XXXX",LEN(B2)=11),AND(LEFT(B2,3)="XXXX",LEN(B2)=11).
The error message I receive is as follows:
excel error message
Title: "Excel customer data validation for chars and numbers"
...I have the feeling it's not just about validating XXXX0000000 but it's about the pattern of characters and numbers. Therefor try:
Formula in B1:
=IF(ISERROR(FILTERXML("<t><s>"&A1&"</s></t>","//s[translate(substring(.,1,4), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','')=''][string-length()=11][substring(.,5)*0=0]")),"Invalid","Valid")
Where:
//s[translate(substring(.,1,4), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','')=''] - Check if when we translate the first 4 characters to nothing this also equals empty string;
[string-length()=11] - Check that node is 11 characters long;
[substring(.,5)*0=0] - Check that substring from 5th position onwards equals zero when multiplied by zero.
Note: FILTERXML() is case sensitive and is currently checking for uppercase alpha-chars.
EDIT:
To use this in data-validation; Ditch the IF() since you don't need that in validation and nest the remainder in NOT():
=NOT(ISERROR(FILTERXML("<t><s>"&A1&"</s></t>","//s[translate(substring(.,1,4), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','')=''][string-length()=11][substring(.,5)*0=0]")))
When you select your range, make sure the validation rule has the topleft cell in the reference.
You have two formulas but no joining of them
IE you have an OR formula
=OR((LEFT(B2,3)="XXXX",LEN(B2)=11)
Which will return a true/false answer
You also have an AND formula
=AND(LEFT(B2,3)="XXXX",LEN(B2)=11)
Which will return a true/false answer
when you work through it you are being given a return of:
=True(or false), true (or false)
That isn't a formula and is causing the error output
I think you want to use an IF statement to join them and get an output as desired:
E.g.
=If(OR(LEFT(B2,3)="XXXX",LEN(B2)=11),AND(LEFT(B2,3)="XXXX",LEN(B2)=11), DO SOEMTHING IF TRUE, DO SOMETHING IF FALSE)
I suggest this:
OR(LEFT(B2,3)="XXX",LEN(B2)=11,AND(LEFT(B2,3)="XXX",LEN(B2)=11))
It corrects the number of characters error and sorts the logic.

Excel - multiple value search across multiple columns or one column with multiple values

I have 7 criteria = TMO-1 through to TMO-7
I have two scenarios to search from.
i have either got a single excel with TMO-6, TMO-201, TMO-67,... etc (some have a lot of values)
or i have split the cell up so the values are all in individual cells such that [TMO-6][TMO-201][TMO-67] etc
I have tried two equations from each. for the first one (the preferred solution) i have tried:
=IF(IFERROR(SEARCH("TMO-1",AB8),0) > 0, "TMO-1",IF(IFERROR(SEARCH("TMO-2",AB8),0) > 0, "TMO-2", "false"))
the problem with that is it finds anything that starts with TMO-1, so will show true if TMO-12 is in the cell.
For option 2 i tried:
=IF(AB9:AR9=TMO-1, TMO-1, IF(AB9:AR9=TMO-2, TMO-2, IF(AB9:AR9=TMO-3, TMO-3,IF(AB9:AR9=TMO-4, TMO-4, IF(AB9:AR9=TMO-5, TMO-5, IF(AB9:AR9=TMO-6, TMO-6, IF(AB9:AR9=TMO-7, TMO-7, "N/A")))))))
and i get the error #spill
any ideas ?
Assuming:
ms365 (Hence the #SPILL error);
The option between concatenated values or seperated (hence AB8 against AB9:AR9);
All numbers are prepended with TMO-;
You are looking for the 1st match in sequence (1-7);
If no match is found, you want to return "Not Found".
First thing that came to mind is to just keep the comma-seperated data in AB8 and use a simple trick to concatenate the delimiters with the sequence:
=ISNUMBER(FIND("-"&SEQUENCE(7)&",",A1&","))
To put that in practice, try:
Formula in B1:
=IFERROR(MATCH("X",IF(ISNUMBER(FIND("-"&SEQUENCE(7)&",",A1&",")),"X"),0),"Not Found")
Other options:
=#IFERROR(SORT(FILTERXML("<t><s>"&SUBSTITUTE(A1,", ","</s><s>")&"</s></t>","//s[substring(.,5)<8]")),"Not Found")
Or, using the insider BETA-functions:
=LET(X,MIN(--DROP(TEXTSPLIT(A1,"-",", "),,1)),IF(X<8,"TMO-"&X,"Not Found"))

Checking if a list starts / ends with any one of many strings in a second list

In excel, what's the best way to check if a list of strings in a column start or end with another list of strings?
Example:
First List:
Reddy
CodeRed
Zabby
KaBlueY
Second List: Red, Blue, Blop, Blurp
The solution should return:
Reddy - TRUE (because it contains 'red' from the second list in the start or end position)
CodeRed - TRUE (because it contains 'red' from the second list in the start or end position)
Zabby - FALSE (because it does not contain any strings from the second list in the start or end position.
KaBlueY - FALSE (because it does not contain any strings from the second list in the start or end position.
Edited Answer:
The question has been changed, and so should my answer to make it current:
If the second argument of SEARCH function is a range, you may use this formula.
Solution #4: Check if any of the strings in a range contain a substring
=OR(ISNUMBER(SEARCH("red",range)))*1
Result: 1
=OR(ISNUMBER(SEARCH("redX",range)))*1
Result: 0
Same explanation as Solution #1 below but instead of searching for a substring in a "parent" string, it searches multiple strings and is made possible by creating an array formula and can only be done by pressing CTRL+SHIFT+ENTER. Check for {} around your formula in the formula bar to make sure that you created an array formula.
Since there are multiple results in an array formula, wrap it with OR function to see if any of the strings in a range contain the string that you're looking for. Finally, simply multiply it by 1 to convert the resulting boolean values to its numerical values.
Hope it helps!
Original Answer:
There are number of ways to do this. You may use SEARCH or SUBSTITUTE function, to parse the string, in combination with other functions such as those that returns boolean values, to check the expected result against the return value of the former. Finally, to convert boolean values into its numerical values, simply multiply it by 1.
Here are some examples to get you started:
Solution #1
=ISNUMBER(SEARCH("red","reddy"))*1
Result: 1
=ISNUMBER(SEARCH("redX","reddy"))*1
Result: 0
If it is able to find the substring red within the "parent" string reddy, the SEARCH function returns a number—the position of the substring you're looking for. Otherwise, like in the case of redX, it returns #VALUE!. To hide the ugly #VALUE! error message as well as to show a more appropriate message than simply showing the position of the substring, wrap it with ISNUMBER function to return TRUE or FALSE. And if you'd like to convert it to its numerical values, multiply it by 1.
Solution #2
=IF(SUBSTITUTE("reddy","red","anyText")="reddy",FALSE,TRUE)*1
Result: 1
=IF(SUBSTITUTE("reddy","redX","anyText")="reddy",FALSE,TRUE)*1
Result: 0
Here, the resulting string from the SUBSTITUTE function is compared against the "parent" string by wrapping it with IF function, which in turn returns a boolean value that can be converted into a numerical value by multiplying it by 1.
Solution #3
=NOT(EXACT("reddy",SUBSTITUTE("reddy","red","anyText")))*1
Result: 1
=NOT(EXACT("reddy",SUBSTITUTE("reddy","redX","anyText")))*1
Result: 0
This is just a variation of the formula presented in Solution #2. It uses EXACT function to check if the resulting string from the SUBSTITUTE function is exactly the same as the old string (which I called the "parent string" in Solution #1). If it is exactly the same, it means nothing were substituted because it didn't find the string you're looking for. Since EXACT function returns TRUE if the two strings are an exact match, which means nothing has changed, which also means, it didn't find the string you're looking for, you need to reverse the result by wrapping it with NOT function. Again, if you'd like to convert it to its numerical form, simply multiply it by 1.
Hope it helps!
References:
SEARCH
ISNUMBER
OR
SUBSTITUTE
IF
EXACT
NOT

Excel Nested IF AND

I have the following formula:
=IF(AND(A1=0,A3="","1 item"),
IF(AND(A1=0,A3="Exclude","1 item"),
IF(AND(A1=1,A3="Exclude","1 item","2 items"))))
3 combinations of cell values in A1 and A3 return text which I'm calling "1 item"
Only 1 combination of cells value returns text which I'm calling "2 items".
The only combination to return "2 items" is where A1=1 AND A3="".
The formatting is wrong but I'm not sure where.
Any help would be greatly appreciated.
this is the correct formula -
brackets of AND() were not properly closed.
=IF(AND(A1=0,A3=""),"1 item",IF(AND(A1=0,A3="Exclude"),"1 item",IF(AND(A1=1,A3="Exclude"),"1 item","2 items")))
Excel's IF expects three parameters: Condition, What to do if condition is TRUE, and what to do if condition is FALSE.
I'll re-format your formula so you can see where the error is:
IF( AND(A1=0,A3="","1 item") ,
IF(AND(A1=0,A3="Exclude","1 item"),
IF(AND(A1=1,A3="Exclude","1 item","2 items")
)
)
)
As you can see
For the first IF you are not providing what to do if condition is FALSE,
The same for the second IF,
The third IF has no definition of what to do if the condition is TRUE or FALSE.
Hope this helps you.
UPDATE
Following your comment (which is still not clear to me), hereinafter I'm providing simple rules you may use to construct your formula correctly:
Write your formula as a piece of text (like the example I show above) so that you can easily read, edit and verify it,
Remember that Excel's IF has three parameters: Condition, result when condition is TRUE and result when condition is FALSE,
Within any of these three parameters, you can include whatever you want PROVIDED that the result is compliant with what the function expects for that parameter; for instance, writing for the first parameter 3=8 is completely legal since the result is FALSE (while 4=2*2 would yield TRUE).
Having this in mind, here is the formula I think you are looking for (WARNING!!! I'm not sure I understood what you need, but if not, changing it should be very easy for you now):
IF(AND(A1=1,A3=""),"2 items","1 item")
This is based on your wording: The only combination to return "2 items" is where A1=1 AND A3="".

Excel strip the bracket and display its value

I am new to excel, I need to remove the M from the string and if the value is in bracket, set it as negative, else set it as positive. But I only managed to do it for positive, how can I write a function that fulfills the mentioned condition?
If G1 value is (100M) then show -100
If G1 value is 100M then show 100
=LEFT(G1,LEN(G1)-1)
=VALUE(IF(LEFT(G1,1)="(",SUBSTITUTE(LEFT(G1,LEN(G1)-2),"(","-"),LEFT(G1,LEN(G1)-1)))
I'm sure there are quite a few ways to doing this but there are the basic steps.
First you need to check your string for the letter M with =search("What",Where). This returns the location of the character if it exists and #VALUE if not.
Next we need to evaluate if the M was found in our search, this can be done with =IFERROR(value) where it will return true if the character is not found.
Lastly we need to wrap it all in a =IF(value, true, false) statement. I'm using =VALUE(string) to convert the value from a string to a number
=IF(IFERROR(SEARCH("M",A2)),-VALUE(LEFT(A2,LEN(A2)-1)),VALUE(A2))
The drawback with an approach is it does not check that M is the last letter in the string, so it would fail with something like 100M100, this could be easily tested for and corrected by checking for the Position of M with =SEARCH() and only returning =SEARCH()-1 characters with =LEFT(A1,SEARCH()-1)
Like:
=IF(IFERROR(SEARCH("M",A1)),-VALUE(LEFT(A1,SEARCH("M",A1)-1)),VALUE(A1))
If A1 was 100M100 then it would return -100
UPDATE:
I originally misread the question missing the parenthesis. both Abe Gold and Tom Sharpe had correctly done this so I will update my fix my mistake. In this case, assumed that and M was significant to the sign of the result and the parenthesis were redundant. So to correct my answer I would do the following
=if(IFERROR(search(")",G1)),-VALUE(right(left(G1,search(")",G1)-2),SEARCH(")",G1)-3)),value(LEFT(G1, LEN(G1)-1)))
=IF(LEFT(G1)="(",-MID(G1,2,LEN(G1)-3),--LEFT(G1,LEN(G1)-1))
This is nicer i think
=VALUE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(G1,"M",""),")",""),"(","-"))
Not sure of all the conditions, but for the following
G1 might be numbers with or without the M and the (...)
You always want to return the number if present.
If that is the case, then simply:
=VALUE(SUBSTITUTE(G1,"M",""))
You have not indicated what you would want for a return should the value in G1 be non-numeric. Just wrap the above in an IFERROR function to allow for that.

Resources