You are on page 1of 10

5/3/2016 Excel formula: Cell contains specific text | Exceljet

Cart Login

Quick, clean, and to the point


Training Videos Functions Formulas Shortcuts

Search...

Cell contains speci c text

= ISNUMBER(SEARCH(substring,text))

Related formulas: 

Count cells that contain speci c text


Cell contains one of many things
Highlight cells that contain
Range contains speci c value
Count cells that contain either x or y

If you need to check if a cell contains a substring (speci c text), you can  do so with the SEARCH function together with the ISNUMBER
function. In the generic form of the formula (above), substring is the speci c text you are testing for, and text represents text in the cell
you are checking.

You can use this formula to nd cells that contain one word, or part of a word.

How the formula works

The SEARCH function returns the position of substring when it's found in text, and the #VALUE! error if not. The ISNUMBER function
returns TRUE for numbers and FALSE for anything else. So, if SEARCH nds substring, it returns the position as a number, and
ISNUMBER returns TRUE. 17However, if SEARCH
12 doesn't nd substring, it returns a #VALUE! error, causing ISNUMBER to return FALSE.
41  
shares
6 4

https://exceljet.net/formula/cell­contains­specific­text 1/10
5/3/2016 Excel formula: Cell contains specific text | Exceljet

If you want this formula to be case-sensitive, you can replace the SEARCH function with the FIND function like so:

= ISNUMBER(FIND(substring,text))

If you want to do something more than just test whether a cell contains speci c text, you can wrap the formula in an IF statement like
this:

= IF(ISNUMBER(SEARCH(substring,text)), "Yes", "No")

Instead of returning TRUE or FALSE, the formula above, will return "Yes" if substring is found and "No" if not.

Looking for more than one thing?

If you need to test a cell to see it contains one of many things, see this formula.

300 Formula examples | Formula video training

Related functions: 

Excel SEARCH Function


Excel ISNUMBER Function
Excel FIND Function

Author: 
Dave Bruns

241 Comments exceljet 
1  Login

  Recommend  4 ⤤ Share Sort by Best

Join the discussion…

Jorge  •  6 months ago
I have teh following... Envoy (C) in A1 and Train (P) in A2. I need aformula in B1 and B2 to recognise C and P only.
1 △   ▽ • Reply • Share › 

Dave Bruns  Mod   > Jorge   •   6 months ago

I don't understand the goal, but If C and P always appear in parentheses, and always at the end, you could do something like:

=IF(RIGHT(A2,3)="(P)","contains P",IF(RIGHT(A2,3)="(C)","contains C","something else"))
△  ▽ • Reply • Share › 

Jorge > Dave Bruns  •  6 months ago
Quick one. 
Envoy(C) Time in A1
Station (P) Markup in A2
Goal :
C in B1
P in B2
I have tried Replace,Find and Search and MID but cannot get it. Please note that, C and P in cells A1 and A2 are in different positions (not
fixed positions)
Many thanks
Jorge
△   ▽ • Reply • Share › 
https://exceljet.net/formula/cell­contains­specific­text 2/10
5/3/2016 Excel formula: Cell contains specific text | Exceljet
△  ▽

Dave Bruns  Mod   > Jorge   •   6 months ago

In that case, just use the original formula at the top of this page and test for the substrings "(C)" and "(P)". You can use them as you
like inside IF.
△  ▽ • Reply • Share › 

Jorge > Dave Bruns  •  6 months ago
I have tried MID but it does not pick up a value. ;­(
△  ▽ • Reply • Share › 

Dave Bruns  Mod   > Jorge   •   6 months ago

No, the formula at the TOP of this page. So, something like:

=IF(ISNUMBER(SEARCH("(P)",A1)),"contains P",IF(ISNUMBER(SEARCH("(C)",A1)),"contains C","something else"))

Will test for (C) and (P) anywhere in A1.
△  ▽ • Reply • Share › 

Jorge > Dave Bruns  •  6 months ago
Of course, silly me.Thank you once again.
△  ▽ • Reply • Share › 

Manu Sachdeva > Dave Bruns  •  6 months ago
Hi Dave, Please check my response on Jorge's post, this is what he was looking for..

Kindly reply
△  ▽ • Reply • Share › 

Jorge > Manu Sachdeva  •  6 months ago
Hi Guys
Thank you for your post. Dave Bruns,you cracked it. Thank you and Happy Halloween guys....
Jorge
1 △   ▽ • Reply • Share › 

Yusuf Hamdy  •  10 days ago
if i need to select a range of substring???? what can i do
△  ▽ • Reply • Share › 

Dave Bruns  Mod   > Yusuf Hamdy  •   9 days ago

If you need to check for more than one substring, try this formula instead.
△  ▽ • Reply • Share › 

Asim  •  13 days ago
I have a problem on my assignments the task is "in cell h3 enter a formula/function that uses the range of your second worksheet to calculate the
mark_up, the content I have been giving is for the code " :a 1.7 b 1.6 c 1.5 d 1.4 e 1.3 f 1.2" and the mark_up is "A,B,c,d,e,d" I really don't understand this
△  ▽ • Reply • Share › 

Sunil  •  a month ago
Thank you :)
△  ▽ • Reply • Share › 

JWB  •  a month ago
Hello Dave,

In the formula below (resides in cell E11), searching D11 for 280, 300 and 320 provide the desired result. Searching for R280, R300, and R320 result in
#N/A in E11. I tried enclosing R280 in quotes. I tried FIND instead of SEARCH. I tried ISTEXT in place of ISNUMBER. Please advise. I parsed it for easier
reading. Thank you for any help you can provide.

=
IF(ISNUMBER(SEARCH(280,$D11)),VLOOKUP($D11,'280'!$A$19:$P$39,4,FALSE),
IF(ISNUMBER(SEARCH(300,$D11)),VLOOKUP($D11,'300'!$A$19:$P$39,4,FALSE),
IF(ISNUMBER(SEARCH(320,$D11)),VLOOKUP($D11,'320'!$A$19:$P$39,4,FALSE),
IF(ISNUMBER(SEARCH(R280,$D11)),VLOOKUP($D11,'280'!$A$54:$P$74,4,FALSE),
IF(ISNUMBER(SEARCH(R300,$D11)),VLOOKUP($D11,'300'!$A$54:$P$74,4,FALSE),
IF(ISNUMBER(SEARCH(R320,$D11)),VLOOKUP($D11,'320'!$A$54:$P$74,4,FALSE),
0))))))
△  ▽ • Reply • Share › 

Dave Bruns  Mod   > JWB  •   a month ago

The #N/A is being thrown by VLOOKUP, so the problem is there somewhere. I would debug with F9 or use Excel's evaluate feature to step through
and trace the problem.
https://exceljet.net/formula/cell­contains­specific­text 3/10
5/3/2016 Excel formula: Cell contains specific text | Exceljet
and trace the problem.
△  ▽ • Reply • Share › 

JWB > Dave Bruns  •  a month ago
The VLOOKUPs are all the same in syntax and only differ as to the range they look in. The ranges all check out fine. Thinking that the "R" in
R280 might be the cause, I changed the "R" to a "9" so that the value being searched is all numeric. Also, all cells in SEARCH and are cell
format "General." Nothing has helped.
△  ▽ • Reply • Share › 

Dave Bruns  Mod   > JWB  •   a month ago

I would enclose the substring in double quotes, i.e. "R280". (Not necessary if you pick up the substring from another cell).

If you still have trouble, I would split the formula into 2 parts (ISNUMBER and VLOOKUP) to make sure you're getting what you
expect from each.

Make sure you are getting TRUE or FALSE from ISNUMBER + SEARCH, and that VLOOKUP is returning a valid result based on the
arrays and lookup values you are providing.
△  ▽ • Reply • Share › 

sudhakar jana  •  a month ago
hi Dave , i have a requirement in excel. I get data in one of the date column as "2015­03­01 12:28:45 PST" or "2015­03­01 12:28:45 PDT". yes, there is a
PDT/PST at the last. and i need this to get converted to IST ( Indian Standard Time).Eg: || "2015­03­01 12:28:45 PST" ­­> should be ­­> 2015­03­01
01:58:45 || (since PST + 13:30 hrs gives IST. Similarly, for PDT, + 12:30 hrs . After conversion the value shld be only datetime value . As i need this time to
compare, calculate the with other datetime values. Hope i am clear with my issue. It may be a formula or a macro to convert the whole column. Advance
thanks for your help
△  ▽ • Reply • Share › 

Dave Bruns  Mod   > sudhakar jana   •   a month ago

You'll need to approach in steps. First, convert the text representation of the the datetime into a value Excel will recognize. For this, you see this
formula: Convert date string to date time

Once you have a proper datetime, you can perform any time zone conversion you want. See: convert time to time zone. If you're working with dates
and times together, use the simple version a the bottom of the page.

Let me know if that helps.
△  ▽ • Reply • Share › 

Ashley P  •  2 months ago
Hello I am new to excel. I just created the search box for my sales lead spread sheet. But do not know what you mean by "wrap formula in IF statement."
How do I perform this step?
△  ▽ • Reply • Share › 

Dave Bruns  Mod   > Ashley P  •   2 months ago

The formula on this page will return either TRUE or FALSE, which means you can use it inside of IF, and take one action for TRUE and a different
action for FALSE.

If you're new to the idea of logical formulas and statements, have a look at this video: https://exceljet.net/plc/how­t...

Let me know if you still have questions.
△  ▽ • Reply • Share › 

Ashley P > Dave Bruns  •  2 months ago
Thank you Dave. I actually am still a bit confused as I am not even excel intermediate lol. What does wrapping a function mean? How do
you do it?
△  ▽ • Reply • Share › 

Dave Bruns  Mod   > Ashley P  •   2 months ago

Wrap is just a casual way to say "embed" in this case, as in "embed the search formula inside an IF function". So:

=ISNUMBER(FIND(C4,B4)) // returns TRUE or FALSE

=IF(ISNUMBER(FIND(C4,B4)), "Yes", "No") // wrapped in IF
△  ▽ • Reply • Share › 

Ashley P > Dave Bruns  •  2 months ago
Ah! got it. So then where would I embed the formula? Do I highlight the search box and embed the IF(ISNUMBER...) there?
△  ▽ • Reply • Share › 

Dave Bruns  Mod   > Ashley P  •   2 months ago

I'm not sure what your worksheet looks like or exactly what you need do to. Are you following the video here:
https://exceljet.net/tips/how­...

https://exceljet.net/formula/cell­contains­specific­text 4/10
5/3/2016 Excel formula: Cell contains specific text | Exceljet

If so, are you stuck on a step?
△  ▽ • Reply • Share › 

Ashley P > Dave Bruns  •  2 months ago
Hi Yes. This was a wonderful video. I did follow the steps up until it said to wrap the function. I am not sure how to embed the
function in order to prevent the search from staying stuck on highlighted cells. Attached is my very basic spreadsheet with over 5000
rows

△  ▽ • Reply • Share › 

Dave Bruns  Mod   > Ashley P  •   2 months ago

OK, I see. You have the search working, but want to stop the highlighting when blank.

You just need to replace the formula you are currently using for the conditional formatting rule with a version "wrapped" in IF.
Assuming you named the search box as shown in the video, your new formula will look like this:

=IF(ISBLANK(search_box),0,original_formula)

Where original_formula is the formula you have now.

Translated: IF the search_box is blank, return zero. If not, return the result of the original formula (which is a positive number when
the search text is found).
△  ▽ • Reply • Share › 

Ashley P > Dave Bruns  •  2 months ago
Thank you so much. I finally understand how to plug it in. It does work, however whenever i type in to search a word the excel doc
stops functioning and closes out. Could it be that the spreadsheet is too large? This could grow into 10000 + rows.
△  ▽ • Reply • Share › 

Dave Bruns  Mod   > Ashley P  •   2 months ago

Ashley ­ I just ran a quick test on a list with over 30,000 rows, and it worked fine, so I don't think you should be hitting any limits.

One thing to try: copy the formula you're using in your rule (so you have it handy) then clear all conditional formatting rules, select
all the data, and add a new rule again. Sometimes, Excel will add a lot new rules if the data has been manipulated and this could
cause performance problems.
△  ▽ • Reply • Share › 

Ashley P > Dave Bruns  •  2 months ago
Thank you Dave.

I've cleared previous rules but am still having the same issue. Just to confirm am I inserting the correct data into the formula? For
example if I had 5000 rows and 7 columns, I would then plug into the IF rule ...
(search_box,$A1:A:5000&$B1:B5000&$C1:C1000...)and so on?
△  ▽ • Reply • Share › 

Dave Bruns  Mod   > Ashley P  •   2 months ago

Your formula isn't correct. You don't want to include ranges, but just row references, as in the example:

=SEARCH(search_box,$C5&$D5&$E5&$F5)

So, not $A1:A:5000&$B1:B5000, but rather $A1&$B1&$C1, etc. with the row numbers keyed to your data.

The range is already determined by the selection you make before you create the rule.
△  ▽ • Reply • Share › 

Ashley P > Dave Bruns  •  2 months ago
Yay! it works now.

https://exceljet.net/formula/cell­contains­specific­text 5/10
5/3/2016 Excel formula: Cell contains specific text | Exceljet

I just have one more question. Is it possible to enter a rule or formula so that when typing the information that youre looking for in
the search box can actually take you to the row, instead of highlighting it­ with you having to search for the highlight?
△  ▽ • Reply • Share › 

Dave Bruns  Mod   > Ashley P  •   2 months ago

Great ­ glad you got it working! To move directly to highlighted rows requires VBA. It's not difficult if you know how to use VBA, but
I don't have a solution with instructions written up at this point, sorry.
△  ▽ • Reply • Share › 

Ashley P > Dave Bruns  •  2 months ago
Thank you for everything. You've helped so much!
△  ▽ • Reply • Share › 

KRN  •  3 months ago
Hi. I'm trying to write an AND function. One of the arguments is that G3 contains certain text.So far, I
have....=IF(AND(IF(ISNUMBER(SEARCH("MODULE*",G3)),TRUE,FALSE))=TRUE,C3="PROGRAM",OR(D3="City 1",D3="City 2",D3="City
3",D3="City 4", D3="City 5")),"PRE­FY16 MODULE","") I can't get this to work. Any help would be greatly appreciated.
Thanks!
△  ▽ • Reply • Share › 

KRN > KRN  •  3 months ago
Answered my own question, at least most of it...=IF(AND(IF(ISNUMBER(SEARCH("MODULE*",G3)),1,0)=1,C3="PROGRAM",OR(D3="City
1",D3="City 2",D3="City 3",D3="City 4", D3="City 5")),"PRE­FY16 MODULE","") this works, except one of the cities appears to match, but is
coming up false?
△  ▽ • Reply • Share › 

KRN > KRN  •  3 months ago
There was a space after the city name...any easy way to make that not matter? I don't want to use search in all of them.
△  ▽ • Reply • Share › 

Dave Bruns  Mod   > KRN   •   3 months ago

You might be able to simply part of your formula using the idea in this formula (which searches cells for one of many items):
https://exceljet.net/formula/c...

You can use the TRIM function inside your formula as needed to remove extra space: https://exceljet.net/excel­fun...
△  ▽ • Reply • Share › 

KRN > Dave Bruns  •  3 months ago
Hi Dave,
Thanks for getting back to me. I played with both ideas, but I don't think I can get SumProduct to return text (I could be wrong) and
I cannot figure out where to insert TRIM. Am fine with using either a list or my original and/or statement.
Kristine
△  ▽ • Reply • Share › 

Dave Bruns  Mod   > KRN   •   3 months ago

In that formula, SUMPRODUCT just returns TRUE or FALSE. You would use it to replace only the OR statement in your formula.
Actually, this formula is closer to what you want, since it tests for equality: https://exceljet.net/formula/c...

You would add TRIM like this: =SUMPRODUCT(­­(TRIM(A1)=things))>0
△  ▽ • Reply • Share › 

EM > Dave Bruns  •  3 months ago
Hello Dave,
I'm glad I came across your website... I needed guidance on how to return different values based on text found and excluded from a
cell. For example, if I want D4 to return a "1" if B4 contains "apple", but only if "day" and "away" are not in that same cell, if it
contains "day", "away", and "apple", it would return a "2", if it finds "day" and "apple" it returns a "3", etc. The numbers and
combination of words doesn't matter, I just need to figure out how to do a search that includes specified words, while excluding
others, and returning whatever character I choose for each combination. I hope that made sense and you can help!
△  ▽ • Reply • Share › 

Dave Bruns  Mod   > EM  •   3 months ago

The formulas to do this kind of thing become quite complicated. If you assume formula1 is the formula on this page configured to
find something, and formula2 is configured to find something else (that you don't want to find), you can do something like:

=IF(AND(formula1,NOT(formula2)),1)

You may also want to look at this: https://exceljet.net/formula/c...
△  ▽ • Reply • Share › 

KRN > Dave Bruns  •  3 months ago
https://exceljet.net/formula/cell­contains­specific­text 6/10
5/3/2016 Excel formula: Cell contains specific text | Exceljet
KRN > Dave Bruns  •  3 months ago
That is beautiful. Thank you so much!
△  ▽ • Reply • Share › 

Bruce Kershner  •  3 months ago
I'm trying to pick out cells with "IT" in them and I'm getting all cells with the letters i and t??? Any suggestions for looking for IT or CIO OR CTO and
limiting the results to just that?
△  ▽ • Reply • Share › 

Dave Bruns  Mod   > Bruce Kershner  •   3 months ago

Yes, "it" will probably produce a lot of false hits.

You can try this formula, which searches a cell for one of several things: https://exceljet.net/formula/c...
△  ▽ • Reply • Share › 

Bruce Kershner > Dave Bruns  •  3 months ago
Dave, you're very kind to offer assistance, I wish i understood. This is literally all greek to me. I was wondering if there is any chance I could
get you to write the formula that I should use, if you think there is one to pick out an abbreviation like "IT".

Thanks
△  ▽ • Reply • Share › 

Dave Bruns  Mod   > Bruce Kershner  •   3 months ago

Can you post a screen shot with some sample data, or give some examples of the cells you are trying to flag and those you don't want
to flag?
△  ▽ • Reply • Share › 

Bruce Kershner > Dave Bruns  •  3 months ago
I've got a very simple spreadsheet. 5 columns (a­e) which includes first name, last name, email address, company name and title.
Unfortunately many of the individuals have IT, or CIO instead of spelling it out. I need to find a way of picking them out of a list of 7­
8000. I hope this helps.
△  ▽ • Reply • Share › 

Dave Bruns  Mod   > Bruce Kershner  •   3 months ago

I would first experiment with a formula like this:

=SUMPRODUCT(­­ISNUMBER(SEARCH({"cio"," it","information technology"},E1)))>0

And adjust the list items to suit. Note that I have " it" in there with a space at the start to try and prevent false positives.

This will return TRUE when a match is found, FALSE if not. Wrap the whole formula inside an IF statement to return something else
(i.e. =IF(formula, "flag","")

If the list syntax becomes unwieldy, you can set up a separate list as explained here:

https://exceljet.net/formula/c...

Same formula, but the list is out on its own for easy edits.
△  ▽ • Reply • Share › 

Bruce Kershner > Dave Bruns  •  3 months ago
Dave, I have absolutely no clue what you are talking about or what these formulas mean but you're a genius! It worked perfectly.
Question. I haven't tried it but if I were to add "cto" in the formula, would that work or just screw things up?

I am a big LinkedIn user and I have thousands of contacts. The problem is that it doesn't allow you to export your contacts by
geography, title, etc. so this is a life saver.

Thank you very much!!
△  ▽ • Reply • Share › 

Load more comments

ALSO ON EXCELJET

Excel shortcut survey results Count visible rows only with criteria
10 comments • 4 months ago 2 comments • 2 months ago
Dave Bruns — Yes, sometimes you feel indifferent about a shortcut you see, Dave Bruns — Right. I haven't tested exhaustively but I believe any math
but then you're in the middle of something in Excel and you realize ­ Wait , I operation will "coerce" the TRUE/FALSE values to ones and zeros. Inside …
can …

Random date between two dates Shortcuts to enter data in Excel
2 comments • 6 months ago 6 comments • 2 months ago

https://exceljet.net/formula/cell­contains­specific­text 7/10
5/3/2016 Excel formula: Cell contains specific text | Exceljet
Dave Bruns — To generate random workdays, you can add the WORKDAY Dave Bruns — Thanks, Jon! I sometimes monkey with that setting, but then
function like this: =WORKDAY(RANDBETWEEN(date1,date2)­1,1) … end up setting it back to the default and just use shortcuts to control again.

✉ Subscribe d Add Disqus to your site Add Disqus Add ὑ Privacy

https://exceljet.net/formula/cell­contains­specific­text 8/10
5/3/2016 Excel formula: Cell contains specific text | Exceljet

Popular Topics

Functions | Formulas
Pivot Tables
Conditional formatting
VLOOKUP | IF function
Keyboard shortcuts
Excel experts | Books

I’m an advanced user, but I nd all your tips and tricks useful. My boss always forwards me
her newsletters, so I decided to sign up. - Rachel

Excel video training


Quick, clean, and to the point.
Learn more

Home About Blog Contact Help us Search


© 2012-2016 Exceljet.

TwitterFacebook
Google+
RSS

https://exceljet.net/formula/cell­contains­specific­text 9/10
5/3/2016 Excel formula: Cell contains specific text | Exceljet

https://exceljet.net/formula/cell­contains­specific­text 10/10

You might also like