Multiple nested if statements with the =IF(ISTEXT(SEARCH

paintdrying

New Member
Joined
Mar 28, 2018
Messages
9
So I just started cutting my teeth on some of the more complicated parts of Excel. I want to output one of a variety of text strings in a given cell based on a variety of text strings in a column to the the left. Some sort of fuzzy match would be excellent as well. I'm not using VBA either.

Practical example: output tiger ( in B5) every time Africa or India shows up in (A5), but also output horse of cow (in B5) whenever America or Europe show up in (A5).

Basically is would output a given text (of multiple possible) based on a a given text (of multiple) in the referencing cell .

<bdo dir="ltr">=IF(ISTEXT(SEARCH("Africa",A452)),A453,"lion") I believe this formula here will output lion whenever Africa Is put within the search. But how do I also say (within in the same cell) if the text happens to be America or Europe output cow </bdo>
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Your thinking is off, your test will always return "lion", the "Search" part of your formula is going to return a number, the starting number of Cell A452 if it contains the text you are looking for, in this case Africa. So it will return a 1, or an error if it doesn't match. Either way the "IStext" portion won't ever see text so your If statement will always give you a "False" result, and in your case that will always be "Lion".

You could try this and see if it does what you want though.

Code:
=IF(OR(A452="Africa",A452="India"),"Lion",IF(OR(A452="America",A452="Europe"),"Cow","Neither"))

I may not have fully understood what you want to test for and output, so it might need to be tweaked.
 
Last edited:
Upvote 0
Your thinking is off, your test will always return "lion", the "Search" part of your formula is going to return a number, the starting number of Cell A452 if it contains the text you are looking for, in this case Africa. So it will return a 1, or an error if it doesn't match. Either way the "IStext" portion won't ever see text so your If statement will always give you a "False" result, and in your case that will always be "Lion".

You could try this and see if it does what you want though.

Code:
=IF(OR(A452="Africa",A452="India"),"Lion",IF(OR(A452="America",A452="Europe"),"Cow","Neither"))

I may not have fully understood what you want to test for and output, so it might need to be tweaked.


I think that helped alot. I will try and I really appreciate it!!
 
Upvote 0
One more question, because your advice worked perfectly, this question is a little harder I believe. But what if we want to say we only want the text Africa to be part of the text in the cell on the left. for instance If it said South Africa, lion would still print. Or if It said United States of America, Cow would still print. I think I gets a bit complicated at that point but maybe you inderstand! thank you sir. your helping me do something at work!
 
Upvote 0
One more question, because your advice worked perfectly, this question is a little harder I believe. But what if we want to say we only want the text Africa to be part of the text in the cell on the left. for instance If it said South Africa, lion would still print. Or if It said United States of America, Cow would still print. I think I gets a bit complicated at that point but maybe you inderstand! thank you sir. your helping me do something at work!
 
Upvote 0
Try this:

Code:
=IF(OR(ISNUMBER(SEARCH("Africa",A452)),A452="India"),"Lion",IF(OR(ISNUMBER(SEARCH("America",A452)),A452="Eurpoe"),"Cow","Neither"))
 
Upvote 0
Do you have a way to pay you on bitcoin, as soon as I load my account ill send you 20$ . You saved me alot of time and I would like to help you in return
 
Upvote 0
Glad it worked, and I am glad to give back to this community that has helped me so much, so no payment is required, but the gesture is appreciated.
 
Upvote 0
It seems to only work for the first value though i.e. Africa and America. The ones directly within the search. But Thank you because Im definately getting closer
 
Upvote 0

Forum statistics

Threads
1,215,517
Messages
6,125,290
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top