HOW TO: "If cell contains specific text then return specific text"

Iron Contributor

I'm trying to extract a bunch of specific text combinations from cells and present it in a new cell.

This formula seems to work for two variables but I can't add any more variables too it.



The text I would be searching for would be:







and possibly a couple more.


Is there a way to do this?

38 Replies

Ah, a classic one.


Key words in column F, returned text in column G, text to check in A1.




Dear Reuben Helder,

You may also use the below formula for the task. I have retained the same cell references that have been used by Detlef Lewin in the solution that he has provided.

The formula given by Detlef Lewin can be amended, so that Pi() and column G will not be required.

Vijaykumar Shetye
Spreadsheet Excellence,
Panaji, Goa, India

Dear Reuben Helder,

Kindly note that the below formula which I had given in the provious post, is an array formula.

Array formulas are entered using Control+Shift+Enter instead of Enter.

Vijaykumar Shetye
Spreadsheet Excellence,
Panaji, Goa, India

Vijaykumar Shetye, my formula does not need amending.

And your change from PI() to 1 will possibly give wrong results.




Dear Detlef Lewin,

Thanks for the reply and the correction. What is the significance of using Pi() in the formula?


Viaykumar Shetye,

Spreadsheet Excellence,

Panaji, Goa, India

PI() itself is just a little gag. The lookup value has to be a number greater than 1. So 1.1 would be enough or 2 if you prefer whole numbers.


Hi Reuben Helder,


Good day,


Please refer below formula to add more variable.

If statment is false then I have considered criteria is "NO MATCH"



Is this helful for you? please revert bach.



Thanks & regards,

Manoj P.




Hi Manoj,


It's worth to re-read task requirements and previous posts, your formula is about something different.

Dear Manoj Patgar,

(1)  The problem has been posted on the forum by Reuben Helder because the formula using nested If functions is not adequate, due to its limitations.

The number of items in the text list is large (Sales, Arch, Land, ALL, Contracts, Construction and possibly a couple more), which nested IFs cannot handle. So the same formula with minor changes cannot work. The formula to be used has to be disigned to handle a long list of data.


(2)  The data which is being searched is not MECH or ARCH. It will be like Searching MECH or ARCH within a data list that contain entries like 'ABC MECHANICAL ENGINEERS' or 'XYX ARCHITECTS'. Hence the wild card character (*) has been used.


Is it clear now?


Vijaykumar Shetye,

Spreadsheet Excellence,

Panaji, Goa India




best response confirmed by Reuben (Iron Contributor)

I'm sorry but i see no limitations which could prevent to use nested IF. The only point it is a bit less flexible compare to nested If equivalents.


But what to use depends on goals, in some cases quick hardcording works quite fine.


If use formatting nested if becomes much more clear and editable. Like this

=IF(ISNUMBER(SEARCH("Sales",        B3,1)),"Sales",
IF(ISNUMBER(SEARCH("Arch", B3,1)),"Architecture",
IF(ISNUMBER(SEARCH("Land", B3,1)),"Land",
IF(ISNUMBER(SEARCH("All", B3,1)),"All",
IF(ISNUMBER(SEARCH("Contracts", B3,1)),"Contracts",
IF(ISNUMBER(SEARCH("Construction", B3,1)),"Construction",
"No Match"


If instead of hardcoded strings use references nested IF becomes more flexible. And if add some extra references (nested if) for future strings to find it becomes even more flexible.


    "No Match"

I don't vote for nested IF,  i would like to say where is no limitations here. What to use that's concrete person choice.

Dear Mr. Sergi,


Yes. You are absolutely right.


<it is worth to re-read the question>


I am a beginner in excel and I am always welcome one who gives valuable suggestion.


With best regards,


Dear Mr. Vijaykumar,


Thank you and appreciate your support.

I am beginner and I am always welcome one who want to give valuable suggestions.


Thanks with best regards,


Hi I'm looking to create a formula to calculate how much I spend on groceries a year. For an example:



then display C1 (the $$)

otherwise false

@scmallory , that's a separate question, better to start new conversation with it from here.

Formula could be



@Sergei BaklanI'm having troubles posting in a new thread.


I tested out the formula and I was hoping cells in column D it would spit out the value in column C for anywhere it says "Food Basic" in column B. So the attached Test document.

Thank you,


@scmallory , to start new conversation go to the General Discussion as in my link and click



Formula doesn't work since in column B you have "food basics ", and you compare with "food basics". Due to space texts are different. Trim the cell like

=IF(SUM(--(TRIM(B1)={"nofrills","food basics","Loblaws","sobeys"})),C1)

@scmallory , good, thank you for the confirmation

Not OP, but this was exactly what I was looking for, thank you!