Forum Discussion
Search for text within a cell and returning value based on what is found or leave the cell blank
Thank you! How do I add to this formula logic to return a blank (or $0) if neither apple or orange are a word in cell C3? m_tarler
- miked2525Nov 01, 2024Copper Contributor
Hi!
What did I do wrong here? I'm looking to return one of these values based on cell V3 containing one of these words OR return a " " (blank) if none of these words are present in cell V3. I'm getting a "
=IF(OR(ISNUMBER(SEARCH("apple",V3)),"$1","",ISNUMBER(SEARCH("orange",V3))),"$2","",(ISNUMBER(SEARCH("banana",V3)),"$3","",ISNUMBER(SEARCH("grape",V3))),"4","")
- miked2525Nov 01, 2024Copper Contributor
Hi!
What did I do wrong here? I'm looking to return one of these values based on cell V3 containing one of these words OR return a " " (blank) if none of these words are present in cell V3. I'm getting a "
=IF(OR(ISNUMBER(SEARCH("apple",V3)),"$1","",ISNUMBER(SEARCH("orange",V3))),"$2","",(ISNUMBER(SEARCH("banana",V3)),"$3","",ISNUMBER(SEARCH("grape",V3))),"4","")
- m_tarlerNov 01, 2024Bronze Contributor
miked2525 first of all I'm not sure what you are getting out and how it is wrong, please clarify. Are you saying instead of a blank space you are getting a quotation mark? If so you may have too many quotes in the formula so """" would return a " but if you are trying to say something else please clarify.
I will also assume you copy paste the formula and here I will 'break it dow' and make it a bit more readable:
=IF( OR( ISNUMBER(SEARCH("apple",V3)), "$1", "", ISNUMBER(SEARCH("orange",V3)) ), "$2", "", ( ISNUMBER(SEARCH("banana",V3)), "$3", "", ISNUMBER(SEARCH("grape",V3)) ), "4", "")so the above formula (from your message makes no sense and you should be getting an error.
on line 1 you start with an IF statement which has 3 parts: condition, if_true, if_false but in the present format you have 6 parts being passed to it.
on line 1 you also start an OR() as the conditional to the IF but the OR grouping doesn't make sense.
This all aside I think you are trying to take what I gave you prior and expand it to 4 items instead of 2.
Maybe on of the following is what you are looking for:
The first is a cascading or nested IF(). In each case it checks a condition and gives a return if_TRUE but if_false a new IF() is embeded. Notice how I indent each IF showing how each is a sub-part to the one above. If you highlight this whole formula you can paste it into excel IF you paste directly into the formula bar at the top of the sheet. (If you try to paste onto a cell it will break across multiple cells and won't work)
=IF( ISNUMBER(SEARCH("apple",V3)), "$1", IF(ISNUMBER(SEARCH("orange",V3))), "$2", IF(ISNUMBER(SEARCH("banana",V3)), "$3", IF(ISNUMBER(SEARCH("grape",V3)), "4", "" ) ) ) )the second option and what I might recommend is using IFS(). Using IFS() you must give an EVEN number of arguments because they are pairs of conditions and if_true. So it will go through the list and if condition is true it will output the next item, if not it will go to the next condition and so on. The last condition I entered is TRUE (you could also enter 1=1 or just 1 or anything excel will evaluate as TRUE) so the if nothing else it true then output "".
=IFS(ISNUMBER(SEARCH("apple",V3)),"$1", ISNUMBER(SEARCH("orange",V3)),"$2", ISNUMBER(SEARCH("banana",V3)),"$3", ISNUMBER(SEARCH("grape",V3))),"$4", TRUE,"")On another note each output in these formulas is TEXT like: "$1". HOWEVER if you replace the "$1" with just the number 1 then it will be numberical VALUE (i.e. you can use SUM and other functions on it). Then you just go to the Number Format section on the Home tab and tell excel to show those values as currency (i.e. show the $ )