Home
How to Create a Google Sheets IF Formula When a Cell Contains Specific Text
Checking if a cell contains a specific string of text is one of the most common tasks in data management. Whether you are categorizing product lists, flagging late invoices, or filtering customer feedback, mastering the "IF contains" logic in Google Sheets is essential for automation.
Google Sheets does not have a single function called IFCONTAINS. Instead, users must combine the IF function with other search-based functions to achieve this result. This guide explores the most effective methods to build these formulas, ranging from simple keyword checks to advanced pattern matching.
Quick Answer: The Standard "IF Contains" Formula
If you need a quick solution that is not case-sensitive, use this combination of IF, ISNUMBER, and SEARCH:
=IF(ISNUMBER(SEARCH("keyword", A1)), "Yes", "No")
This formula searches for "keyword" inside cell A1. If found, it returns "Yes"; otherwise, it returns "No".
Why Google Sheets Requires Combined Functions
To understand why we use the combination of IF, ISNUMBER, and SEARCH, we need to break down how Google Sheets processes strings.
- SEARCH("keyword", A1): This function looks for a string. If it finds the text, it returns a number representing the character position where the text starts. If it does not find the text, it returns a
#VALUE!error. - ISNUMBER(...): Since
IFrequires a TRUE or FALSE value, andSEARCHreturns either a number or an error, we wrap it inISNUMBER. IfSEARCHfound the text (returning a number),ISNUMBERbecomes TRUE. If it failed (returning an error),ISNUMBERbecomes FALSE. - IF(Condition, Value_if_true, Value_if_false): Finally, the
IFfunction takes that TRUE or FALSE and outputs your custom message.
Method 1: Case-Insensitive Search (The Most Common Way)
In most business scenarios, you don't care if a word is capitalized. For example, if you are looking for the word "Paid" in a status column, you want to catch "paid", "PAID", and "Paid".
The Formula
=IF(ISNUMBER(SEARCH("paid", B2)), "Completed", "Pending")
Real-World Example
Imagine you have a list of support tickets in Column B. You want to identify any ticket that mentions the word "refund".
| Ticket Description (Column B) | Status (Column C) |
|---|---|
| Customer requested a refund | =IF(ISNUMBER(SEARCH("refund", B2)), "Action Required", "Normal") |
| Shipping was late | "Normal" |
| Need a REFUND immediately | "Action Required" |
Because SEARCH is case-insensitive, it flags both "refund" and "REFUND".
Method 2: Case-Sensitive Search using FIND
Sometimes, capitalization matters. This is common in SKU tracking, case-sensitive passwords, or specific coding tags. To distinguish between "Apple" and "apple", use the FIND function instead of SEARCH.
The Formula
=IF(ISNUMBER(FIND("Apple", A1)), "Match Found", "No Match")
How it differs from SEARCH
SEARCH("A", "a")returns 1 (Match).FIND("A", "a")returns an error (No Match).
Use this method when your data follows a strict naming convention where uppercase and lowercase letters represent different categories.
Method 3: Checking for Multiple Keywords with REGEXMATCH
If you need to check if a cell contains one of several different words (e.g., "Apple" OR "Orange" OR "Banana"), using multiple nested IF statements becomes messy. The REGEXMATCH function is a much cleaner alternative.
The Formula
=IF(REGEXMATCH(A1, "Apple|Orange|Banana"), "Fruit Found", "Other")
Why use REGEXMATCH?
- The Pipe Symbol (
|): This acts as the "OR" operator in regular expressions. - Efficiency: You can list dozens of keywords within a single set of quotation marks.
- Note:
REGEXMATCHis case-sensitive by default. To make it case-insensitive, you can use the syntax(?i):=IF(REGEXMATCH(A1, "(?i)apple|orange"), "Found", "Not Found")
Practical Application
Suppose you are analyzing social media comments. You want to flag comments that contain "price", "cost", or "expensive".
=IF(REGEXMATCH(B2, "(?i)price|cost|expensive"), "Pricing Inquiry", "General")
Method 4: Handling Entire Columns with ARRAYFORMULA
Manually dragging a formula down 10,000 rows is inefficient. Google Sheets allows you to apply your "IF contains" logic to an entire column using ARRAYFORMULA.
The Formula
=ARRAYFORMULA(IF(A2:A="", , IF(ISNUMBER(SEARCH("urgent", A2:A)), "Priority", "Standard")))
Breakdown of the logic:
- A2:A: This tells the formula to look at the entire range from row 2 downwards.
- IF(A2:A="", , ...): This is a "cleanliness" check. It tells Google Sheets: "If the cell in column A is empty, leave the result empty." This prevents the formula from filling "Standard" all the way to the bottom of the spreadsheet where there is no data.
- ARRAYFORMULA: This enables the calculation to output a range of values rather than a single cell.
Method 5: Using ISTEXT for Data Validation
It is important to distinguish between "Does this cell contain a specific word?" and "Is the data type in this cell a text string?".
If you want to check if a cell contains any text (as opposed to numbers or dates), use the ISTEXT function.
The Formula
=IF(ISTEXT(A1), "This is text", "This is not text")
When to use ISTEXT:
- Ensuring that a "Comments" column doesn't accidentally contain numerical data.
- Cleaning up data imports where numbers might be stored as text strings.
- Preparing data for visualization tools that require categorical labels.
How to Check if a Cell Does NOT Contain Text
Sometimes the goal is to find what is missing. To check if a cell does not contain a specific string, simply swap the positions of your TRUE and FALSE results in the IF function, or use the NOT function.
Option A (Swapping results):
=IF(ISNUMBER(SEARCH("discount", A1)), "No", "Yes")
(This says: If "discount" is found, return "No", otherwise "Yes".)
Option B (Using NOT):
=IF(NOT(ISNUMBER(SEARCH("discount", A1))), "Apply Discount", "Already Discounted")
Troubleshooting Common Issues
1. The formula returns #VALUE!
This usually happens if you forget to use ISNUMBER. Remember, SEARCH returns an error if the text isn't found. The IF function cannot handle a direct error as a logical test, so you must convert that error into a FALSE using ISNUMBER.
2. Leading or Trailing Spaces
If your search term is " Apple " (with spaces) but the cell contains "Apple", the formula will return FALSE. Use the TRIM function to clean your data before searching:
=IF(ISNUMBER(SEARCH("Apple", TRIM(A1))), "Yes", "No")
3. Wildcards
SEARCH naturally supports wildcards.
- Question mark (
?): Matches any single character. - Asterisk (
*): Matches any sequence of characters. For example,SEARCH("de*t", A1)would find "debt", "department", and "default".
Frequently Asked Questions
How do I check if a cell contains text from a list in another range?
If you have a list of keywords in cells E1:E10 and want to check if A1 contains any of them, use:
=IF(SUMPRODUCT(--ISNUMBER(SEARCH(E1:E10, A1)))>0, "Match", "No Match")
Can I use "IF contains" to change the color of a cell?
Yes, but you don't need the IF part for Conditional Formatting. Just use the custom formula:
=ISNUMBER(SEARCH("keyword", A1))
Then, set your desired formatting (e.g., red background).
Is there a limit to how many characters SEARCH can handle?
Google Sheets can handle strings up to 50,000 characters. For most spreadsheets, you will never hit this limit. However, performance may slow down if you use complex REGEXMATCH or ARRAYFORMULA over hundreds of thousands of rows.
Summary of Methods
| Goal | Recommended Formula |
|---|---|
| Simple search (any case) | =IF(ISNUMBER(SEARCH("text", A1)), "Yes", "No") |
| Search with case sensitivity | =IF(ISNUMBER(FIND("Text", A1)), "Yes", "No") |
| Search for multiple options | `=IF(REGEXMATCH(A1, "word1 |
| Apply to a whole column | =ARRAYFORMULA(IF(ISNUMBER(SEARCH("text", A1:A)), "Yes", "No")) |
| Check if any text exists | =IF(ISTEXT(A1), "Text", "Not Text") |
By combining the logical power of the IF function with string-searching tools like SEARCH, FIND, and REGEXMATCH, you can automate almost any data categorization task in Google Sheets. Choose the method that best fits your needs for case sensitivity and complexity.
-
Topic: Google Sheets Filter string containshttps://img1.wsimg.com/blobby/go/72fc6eb8-20de-4439-bced-6bfc7eecaa8e/downloads/56935916330.pdf
-
Topic: Mastering ISTEXT: Understand Google Sheets Formulas – DashboardsEXCEL.comhttps://dashboardsexcel.com/blogs/blog/istext-google-sheets-formula-explained
-
Topic: Learning To Use The IF Function With Text: A Google Sheets Tutorial - PSYCHOLOGICAL STATISTICShttps://stats.arabpsychology.com/google-sheets-use-if-function-with-text-values/