How to use Excel formula: "If cell contains" (2024)

Rick Akura on

To test for cells containing certain text, you can use a formula that uses the IF function and the SEARCH and ISNUMBER functions. Learn more here.

Excel has a number of formulas that help you use your data in useful ways. For example, you can get an output based on whether or not a cell meets certain specifications. Right now, we’ll focus on a function called “if cell contains, then”. Let’s look at an example.

Jump To Specific Section:

  1. Explanation: If Cell Contains
  2. If cell contains any value, then return a value
  3. If cell contains text/number, then return a value
  4. If cell contains specific text, then return a value
  5. If cell contains specific text, then return a value (case-sensitive)
  6. If cell does not contain specific text, then return a value
  7. If cell contains one of many text strings, then return a value
  8. If cell contains several of many text strings, then return a value

Excel Formula: If cell contains

Generic formula

=IF(ISNUMBER(SEARCH("abc",A1)),A1,"")

Summary

To test for cells containing certain text, you can use a formula that uses the IF function andtheSEARCHandISNUMBERfunctions. In the example shown, the formula inC5 is:

=IF(ISNUMBER(SEARCH("abc",B5)),B5,"")

If you want to check whether or not the A1 cell contains the text “Example”, you can run a formula that will output “Yes” or “No” in the B1 cell. There are a number of different ways you can put these formulas to use. At the time of writing, Excel is able to return the following variations:

  • If cell contains any value
  • If cell contains text
  • If cell contains number
  • If cell contains specific text
  • If cell contains certain text string
  • If cell contains one of many text strings
  • If cell contains several strings

Using these scenarios, you’re able to check if a cell contains text, value, and more.

Explanation: If Cell Contains

One limitation of the IF function is that it does not support Excel wildcards like "?" and "*". This means you can't use IF by itself to test for text that may appear anywhere in a cell.

One solution is a formula that uses the IF function together with the SEARCH and ISNUMBER functions. For example, if you have a list of email addresses, and want to extract those that contain "ABC", the formula to use is this:

=IF(ISNUMBER(SEARCH("abc",B5)),B5,""). Assuming cells run to B5

If "abc" is found anywhere in a cell B5, IF will return that value. If not, IF will return an empty string (""). This formula's logical test is this bit:

ISNUMBER(SEARCH("abc",B5))

Read article: Excel efficiency: 11 Excel Formulas To Increase Your Productivity

Using “if cell contains” formulas in Excel

The guides below were written using the latest Microsoft Excel 2019 for Windows 10. Some steps may vary if you’re using a different version or platform. Contact our experts if you need any further assistance.

1. If cell contains any value, then return a value

This scenario allows you to return values based on whether or not a cell contains any value at all. For example, we’ll be checking whether or not the A1 cell is blank or not, and then return a value depending on the result.

  • Select the output cell, and use the following formula: =IF(cell<>"", value_to_return, "").
  • For our example, the cell we want to check is A2, and the return value will be No. In this scenario, you’d change the formula to =IF(A2<>"", "No", "").
  • Since the A2 cell isn’t blank, the formula will return “No” in the output cell. If the cell you’re checking is blank, the output cell will also remain blank.

2. If cell contains text/number, then return a value

With the formula below, you can return a specific value if the target cell contains any text or number. The formula will ignore the opposite data types.

Check for text

  • To check if a cell contains text, select the output cell, and use the following formula: =IF(ISTEXT(cell), value_to_return, "").
  • For our example, the cell we want to check is A2, and the return value will be Yes. In this scenario, you’d change the formula to =IF(ISTEXT(A2), "Yes", "").

    How to use Excel formula: "If cell contains" (1)

  • Because the A2 cell does contain text and not a number or date, the formula will return “Yes” into the output cell.

Check for a number or date

  • To check if a cell contains a number or date, select the output cell, and use the following formula: =IF(ISNUMBER(cell), value_to_return, "").
  • For our example, the cell we want to check is D2, and the return value will be Yes. In this scenario, you’d change the formula to =IF(ISNUMBER(D2), "Yes", "").

    How to use Excel formula: "If cell contains" (2)

  • Because the D2 cell does contain a number and not text, the formula will return “Yes” into the output cell.

3. If cell contains specific text, then return a value

To find a cell that contains specific text, use the formula below.

  • Select the output cell, and use the following formula: =IF(cell="text", value_to_return, "").
  • For our example, the cell we want to check is A2, the text we’re looking for is “example”, and the return value will be Yes. In this scenario, you’d change the formula to =IF(A2="example", "Yes", "").

    How to use Excel formula: "If cell contains" (3)

  • Because the A2 cell does consist of the text “example”, the formula will return “Yes” into the output cell.

4. If cell contains specific text, then return a value (case-sensitive)

To find a cell that contains specific text, use the formula below. This version is case-sensitive, meaning that only cells with an exact match will return the specified value.

  • Select the output cell, and use the following formula: =IF(EXACT(cell,"case_sensitive_text"), "value_to_return", "").
  • For our example, the cell we want to check is A2, the text we’re looking for is “EXAMPLE”, and the return value will be Yes. In this scenario, you’d change the formula to =IF(EXACT(A2,"EXAMPLE"), "Yes", "").
  • Because the A2 cell does consist of the text “EXAMPLE” with the matching case, the formula will return “Yes” into the output cell.

5. If cell does not contain specific text, then return a value

The opposite version of the previous section. If you want to find cells that don’t contain a specific text, use this formula.

  • Select the output cell, and use the following formula: =IF(cell="text", "", "value_to_return").
  • For our example, the cell we want to check is A2, the text we’re looking for is “example”, and the return value will be No. In this scenario, you’d change the formula to =IF(A2="example", "", "No").

    How to use Excel formula: "If cell contains" (4)


  • Because the A2 cell does consist of the text “example”, the formula will return a blank cell. On the other hand, other cells return “No” into the output cell.

6. If cell contains one of many text strings, then return a value

This formula should be used if you’re looking to identify cells that contain at least one of many words you’re searching for.

  • Select the output cell, and use the following formula: =IF(OR(ISNUMBER(SEARCH("string1", cell)), ISNUMBER(SEARCH("string2", cell))), value_to_return, "").
  • For our example, the cell we want to check is A2. We’re looking for either “tshirt” or “hoodie”, and the return value will be Valid. In this scenario, you’d change the formula to =IF(OR(ISNUMBER(SEARCH("tshirt",A2)),ISNUMBER(SEARCH("hoodie",A2))),"Valid ","").

    How to use Excel formula: "If cell contains" (5)

  • Because the A2 cell does contain one of the text values we searched for, the formula will return “Valid” into the output cell.

To extend the formula to more search terms, simply modify it by adding more strings using ISNUMBER(SEARCH("string", cell)).

7. If cell contains several of many text strings, then return a value

This formula should be used if you’re looking to identify cells that contain several of the many words you’re searching for. For example, if you’re searching for two terms, the cell needs to contain both of them in order to be validated.

  • Select the output cell, and use the following formula: =IF(AND(ISNUMBER(SEARCH("string1",cell)), ISNUMBER(SEARCH("string2",cell))), value_to_return,"").
  • For our example, the cell we want to check is A2. We’re looking for “hoodie” and “black”, and the return value will be Valid. In this scenario, you’d change the formula to =IF(AND(ISNUMBER(SEARCH("hoodie",A2)),ISNUMBER(SEARCH("black",A2))),"Valid ","").

    How to use Excel formula: "If cell contains" (6)

  • Because the A2 cell does contain both of the text values we searched for, the formula will return “Valid” to the output cell.

Final thoughts

We hope this article was useful to you in learning how to use “if cell contains” formulas in Microsoft Excel. Now, you can check if any cells contain values, text, numbers, and more. This allows you to navigate, manipulate and analyze your data efficiently.

We're glad you're read the article up to here :) Thank you :)

Keep Learning

» How to use NPER Function in Excel
» How to Separate First and Last Name in Excel
» How to Calculate Break-Even Analysis in Excel

How to use Excel formula: "If cell contains" (2024)

FAQs

How to use Excel formula: "If cell contains"? ›

Simple IF examples

In this example, the formula in cell D2 says: IF(C2 = 1, then return Yes, otherwise return No)As you see, the IF function can be used to evaluate both text and values.

What is the formula in Excel to check if a cell contains a value? ›

Simple IF examples

In this example, the formula in cell D2 says: IF(C2 = 1, then return Yes, otherwise return No)As you see, the IF function can be used to evaluate both text and values.

What is the formula if a cell contains part text in Excel? ›

To check if a cell includes a particular piece of partial text, use the Excel formula below: =IF(COUNTIF(A1,*abc*),Yes,No). In this example, cell A1 will return a Yes if the string abc appears anywhere in the cell, and a No otherwise.

How do you write an if then formula in Excel? ›

To use the “If “ function in Excel, you start by writing the equal sign (=), followed by “if,” then your condition, and a two-part syntax instructing the program on what to do when your requirements are or aren't met. The syntax usually looks like this: =IF(logical_test, [value_if_true], [value_if_false])

How do you use if condition for text in Excel? ›

How To Use If Function With Text In Excel: Finding Exact Text
  1. Here is a sample formula to show how this can be done: =IF(EXACT(A2,abc),1,0)
  2. This formula will return 1 if there is an exact match and will return 0 in case of no match.
  3. 3.As you can see that there is no exact match, so it has returned us 0.
Feb 13, 2023

How to use ifs formula? ›

The function's syntax is =IFS(logical_test1, value1, [logical_test2, value2], …), allowing up to 127 conditions. It is useful for grading systems, categorizing data, and more. Errors occur if no conditions are met or if arguments are incorrect.

How do you write an if then formula in Excel with multiple criteria? ›

To put two conditions in an IF formula in Excel, you can use the AND or OR function along with the IF function. For example, =IF(AND(A1>50, B1>60), “Pass”, “Fail”) will check if the value in cell A1 is greater than 50 and the value in cell B1 is greater than 60.

Can an Excel cell contain text and a formula? ›

You can include both a formula and text in the same cell in Excel. You can do this in many ways, depending on what you are trying to accomplish. The first screenshot below shows an example of when it may be useful to combine a formula and text in the same cell.

How to count if a cell contains part of text? ›

Select a blank cell to store the counting result, write the formula =COUNTIF(A1:A16,"*Anne*") into it, and press the Enter key (A1:A16 is the range to count cells, and Anne is the partial string). Note: You can use the formula =COUNTIFS(A1:A16,"*Anne*",A1:A16,"*Green*") to count cells that include both substrings.

How do you conditional format if a cell contains certain text? ›

Select the range on which you want to apply the conditional formatting.
  1. Afterward, go to the Home Tab > Conditional Formatting > Highlight Cells Rule > Text That Contains.
  2. Next, in the dialog box, enter the text you want to look for in the data and select the formatting you want to apply to the matched cells.

How do you check if a cell contains specific text from a list in Excel? ›

To check if a cell contains text from a list in Excel, you can use the VLOOKUP, or Vertical Lookup, function. This function will search for a specific value in the first column of a specified range and return a result from another column in the same row.

How to find specific text in Excel cell using formula? ›

Using ISNUMBER Function

Type the formula =ISNUMBER (SEARCH (Yes, B2:B6)) where “YES” is the text to find, B2:B6 is the cell range where you want to find the text. If you want to add a case-sensitive condition, you must use the FIND function in conjunction with ISNUMBER.

References

Top Articles
Weight Loss Magic Soup Recipe - The Best Weight Loss Recipe!
Recipe for Danish Bonfire Bread (Snobrød) - The BEST and easy recipe!
Durr Burger Inflatable
Weeminuche Smoke Signal
Cash4Life Maryland Winning Numbers
Blackstone Launchpad Ucf
Math Playground Protractor
Autobell Car Wash Hickory Reviews
Craigslist Dog Sitter
Becky Hudson Free
World of White Sturgeon Caviar: Origins, Taste & Culinary Uses
Simple Steamed Purple Sweet Potatoes
Discover Westchester's Top Towns — And What Makes Them So Unique
Guilford County | NCpedia
Jackson Stevens Global
Best Forensic Pathology Careers + Salary Outlook | HealthGrad
Vipleaguenba
Osborn-Checkliste: Ideen finden mit System
How your diet could help combat climate change in 2019 | CNN
Homeaccess.stopandshop
Babbychula
Hannaford Weekly Flyer Manchester Nh
Bolsa Feels Bad For Sancho's Loss.
Workshops - Canadian Dam Association (CDA-ACB)
Idle Skilling Ascension
Hrconnect Kp Login
Movies - EPIC Theatres
His Only Son Showtimes Near Marquee Cinemas - Wakefield 12
Duke University Transcript Request
Halsted Bus Tracker
Little Caesars Saul Kleinfeld
Vistatech Quadcopter Drone With Camera Reviews
Flaky Fish Meat Rdr2
Roch Hodech Nissan 2023
Lil Durk's Brother DThang Killed in Harvey, Illinois, ME Confirms
Beaver Saddle Ark
Ket2 Schedule
Zero Sievert Coop
Ljw Obits
Edict Of Force Poe
Ticketmaster Lion King Chicago
Studio 22 Nashville Review
Oxford Alabama Craigslist
Skyward Marshfield
Vérificateur De Billet Loto-Québec
Advance Auto.parts Near Me
Perc H965I With Rear Load Bracket
Grandma's Portuguese Sweet Bread Recipe Made from Scratch
Ingersoll Greenwood Funeral Home Obituaries
The Missile Is Eepy Origin
Códigos SWIFT/BIC para bancos de USA
Latest Posts
Article information

Author: Corie Satterfield

Last Updated:

Views: 5512

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Corie Satterfield

Birthday: 1992-08-19

Address: 850 Benjamin Bridge, Dickinsonchester, CO 68572-0542

Phone: +26813599986666

Job: Sales Manager

Hobby: Table tennis, Soapmaking, Flower arranging, amateur radio, Rock climbing, scrapbook, Horseback riding

Introduction: My name is Corie Satterfield, I am a fancy, perfect, spotless, quaint, fantastic, funny, lucky person who loves writing and wants to share my knowledge and understanding with you.