This is probably too simple but I just can't find my way around it.
I have to cells
A1 B1
high ground low water
So I need a formula that states that if cell A1 contains "high ground" and cell B1 contains the word "water" output "OK" otherwise "no ok"
Thanks in advance
Next formula is working for me:
=if(AND(A2="high ground",(B2=SEARCH("water",B2,1))>0),"ok","not ok")
I'm supposing cell A2 contains high groud, and cell B2 contains low water.
In the if statement there are two conditions: if cell A2= High ground and if cell b2 contains water then Ok else not ok.
Hope it works for you!!
Sorry, next is the right one (whithout HALLAR, instead SEARCH):
please try next:
=IF(AND(A1="high ground",(B1=SEARCH("water",B1,1))>0),"ok","not ok"
For OpenOffice / LibreOffice Calc, the following function should work:
=IF(AND(A1 = "high ground";NOT(ISERROR(SEARCH("water";B1;1))));"OK";"not OK")
or split up on multiple lines with comments:
=IF( # First function: result will depend on condition
AND( # Condition: two sub-conditions have to be TRUE
A1 = "high ground"; # First subcondition: simple equality check
NOT( # Second subcondition
ISERROR( # Check if the embededded function (SEARCH()) returns an error
SEARCH("water";B1;1) # Search B1 for substring. Will throw an error if there's no match in B! for string "water"
)
)
);
"OK"; # Return value if condition is fulfilled;
"not OK" # return value if on of the sub-conditions isn't fulfilled.
)
The NOT(ISERROR(SEARCH("water";B1;1))) is a little bit complicated. Since the SEARCH() function (as well as the FIND() function) throws an error if there's no match, you will have to handle that error, else the complete formula will return an error instead of the string "not ok". For error handling, i put the SEARCH() function into an ISERROR() function, translating the result of SEARCH() into a boolean value (TRUE or FALSE). Since we want a TRUE result if the search finds a match, we have to "invert" the output of ISERROR() using the NOT() function.
Searching for a substring could also be done using regular expressions, but this would require enabling regular expressions in the Calc Program Options; the proposed solution using ISERROR(SEARCH()) should work independently of that config setting.
Try this:
=if(AND(A1="high ground",B1="*water*"),"OK","Not OK")
Sorry my answer before included a wildcard within an If statement and for some reason excel doesn't recognise them.
I have tested this one and it should work for you:
=IF(AND(A1="high ground",ISNUMBER(SEARCH("water",B1))),"OK","Not OK")
Related
I am very newbie in excel, I wanted to make my formula to return matched value instead of TRUE/FALSE
=NOT(NOT(SUM(--NOT(ISERR(SEARCH($D$2:$D$21;$B2))))))
is there anyway this formula can be revised to return like for example: found word "wow" and return the word into the cell instead of TRUE/FALSE?
thank you
Use the =IF function.
=IF(condition; value if true; value if false)
condition is your condition to test. For example $A$1 < 5
value if true is a value returned if condition is true
value if false opposite to previous part, this is a value returned if condition is false.
Following formula will return a $A$1 cell value if less than 5 and too big literally if $A$1's value is bigger or equal to 5:
=IF($A$1<5; $A$1; "too big")
Just combine it with your condition.
You can use IF function:
=IF(logical_test, CONCAT("Found word", $YourWord), "Not found")
This will help You Remember the "Text" must be in " "
=IF(ISNUMBER(SEARCH(substring;"WOW")); "Yes"; "No")
The Value will be only Yes or No , You may change that
There are two cases and I'm not sure which one you need
(1) You have a word like WOW, and you want to find matches in a list of strings like BOWWOW
(2) You have a word like WOW, and you want to find matches for part of it in a list of substrings like OW
The easiest way to do the first one is to use MATCH with a wildcard
=INDEX($D$2:$D$21,MATCH("*"&B2&"*",$D$2:$D$21,0))
For the second one you would need to modify your formula a bit
=INDEX($D$2:$D$21,MATCH(0,(ISERROR(SEARCH($D$2:$D$21,$B$2))+($D$2:$D$21="")),0))
or
=INDEX($D$2:$D$21,MATCH(1,ISNUMBER(SEARCH($D$2:$D$21,$B$2))*($D$2:$D$21<>""),0))
the last two entered as array formulae using CtrlShiftEnter
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.
First post so let me say Excel is NOT my strong suit. I am trying to achieve results using IF/OR, but that may be the wrong choice. All advice and direction will be appreciated.
I have a spreadsheet. Cell F2 will always have the text "TANK" or "CYLINDER". Cell C2 will always have a number. I need to return "PASS" or "FAIL" flag in cell G2 based on the value in C2, BUT those values differ based on the text in F2.
Explanation:
IF F2=TANK & C2<=19 - return PASS,
IF F2=TANK & C2>=20 - return FAIL,
or
IF F2=CYLINDER & C2<=20 - return PASS,
IF F2=CYLINDER & C2>=21 - return FAIL,
Below is one of many options I have tried and apparently I don't know what I'm doing. Any help is appreciated...Thanks
=IF(OR(F2="TANK",F2="CYLINDER"),IF(F2="TANK",IF(C2<=19,"PASS",IF(C2>=20,"FAIL")))),IF(F2="CYLINDER",IF(C2<=20,"PASS",IF(C2>=21,"FAIL")))
I haven't tested it much, but this should be what you are looking for:
=IF(AND(F2="TANK",C2<=19),"PASS",IF(AND(F2="CYLINDER",C2>=20),"FAIL",IF(AND(F2="CYLINDER",C2<=20),"PASS",IF(AND(F2="CYLINDER",C2>=21),"FAIL"))))
Here's a working version:
=IF(F2="TANK",IF(C2<=19,"PASS","FAIL"),IF(F2="CYLINDER",IF(C2<=20,"PASS","FAIL"),"not tank or cylinder"))
However, as you've noticed, long strings of functions within functions all on one line become extremely difficult to read and debug!
You can split up the intermediate steps in your formula into seperate cells - this makes it much easier to see what's going on at a glance. For example, you could have a cell that calculates the maximum value for pass/fail:
A1: if(F2="TANK", 20, if (F2="CYLINDER", 21, -1))
A2: if(C2>=A1,"PASS","FAIL")
(the "-1" is a final "else" case, if neither "TANK" nor "CYLINDER" is true)
Other ideas: if you've got three or more cases (tank, cylinder, widget, thimble...), you can use a vlookup function to return the maximum value. See https://support.office.com/en-us/article/VLOOKUP-function-0bbc8083-26fe-4963-8ab8-93a18ad188a1
I have multiple Excel workbooks in which there are many columns. There will be a column in English and a column in Spanish. What I am trying to do is compare the two columns to see if the Spanish column does indeed have translated text from English. That's easy enough:
IF(A2=C2, "NOT TRANSLATED", "TRANSLATED")
However, there are hundreds of cells that simply do not have values in both the English and Spanish columns. So the formula I used above will say "Yes, these are technically the same value even though they're null, so no translation has been done". This is causing it to seem like there are far too many "NOT TRANSLATED" values than there actually are. This is what I tried:
IF(A2=C2, "NOT TRANSLATED", "TRANSLATED", IF(ISBLANK(A2)=TRUE, "NULL VALUE", "CHECK VALUE"))
That gives me an error though.
I am thinking that I need to have a function that first checks to see if the cell has a value to begin with. If it does, then the formula should proceed to check to see if the two cells have identical values or not. If either cell does not have a value, then it should return "NULL VALUE". Any ideas?
You're effectively giving the IF function 4 parameters with that second formula. IF accepts at least 1 mandatory parameter (the condition) and then 2 optional parameters (what to do if it returns TRUE or FALSE).
Instead you need to nest your IF conditions with something like:
IF(A2=C2, IF(ISBLANK(A2)=TRUE, "NULL VALUE", "CHECK VALUE"), "TRANSLATED")
Which checks to see if A2=C2, if it is then it checks to see if A2 is blank, if it is (and A2=C2 remember) then it returns "NULL VALUE", if it isn't (but A2 is still equal to C2) then it reurns "CHECK VALUE" and if A2 isn't equal to C2 then it returns "TRANSLATED".
Obviously you might want to tweak this for your problem.
Wooo!!! With a little help from you guys I got it. It looks like this:
=IF(AND(ISBLANK(A2)=TRUE; ISBLANK(B2)=TRUE); "NULL"; IF(OR(ISBLANK(A2)=TRUE; ISBLANK(B2)=TRUE); "NOT TRANSLATED"; IF(A2=B2; "NOT TRANSLATED"; "TRANSLATED")))
That one was a monster.
You might find this formula helpful, it will check for a null value in either column
{=IF(OR(A1:B1=""),"Null Value",IF(A1=B1,"Not Translated","Translated"))}
Leave out the curly braces and enter the function using Ctrl+Shift+Enter
You can drag that down for the following results
a a Not Translated
b c Translated
d Null Value
e Null Value
Null Value
f f Not Translated
Try:
=IF(OR(LEN(A2)=0,LEN(C2)=0),"IS NULL",IF(A2=C2, "NOT TRANSLATED", "TRANSLATED"))
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 )