The IF function in Excel is a powerful tool that allows you to perform different actions based on a given condition. When combined with the CONTAINS function, you can create formulas that check if a specific text or value is present within a cell or range of cells. This can be incredibly useful for data analysis, automation, and decision-making processes. In this blog post, we will explore how to use the IF CONTAINS formula in Excel, providing examples and step-by-step instructions to help you master this technique.
Understanding the IF Function

The IF function in Excel is a logical function that evaluates a given condition and returns a specific value based on whether the condition is TRUE or FALSE. The basic syntax of the IF function is as follows:
=IF(condition, value_if_true, value_if_false)
Here's a breakdown of the parameters:
- condition: This is the logical test or expression that you want to evaluate. It can be a comparison between two values, a reference to a cell containing a condition, or a complex formula.
- value_if_true: The value or result that should be returned if the condition evaluates to TRUE.
- value_if_false: The value or result that should be returned if the condition evaluates to FALSE.
For example, the formula =IF(A1 > 10, "High", "Low")
will return "High" if the value in cell A1 is greater than 10, and "Low" otherwise.
Introducing the CONTAINS Function

The CONTAINS function is a powerful tool in Excel that allows you to check if a specific text or value is present within a given cell or range. It returns TRUE if the text is found and FALSE otherwise. The syntax for the CONTAINS function is as follows:
=CONTAINS(cell_reference, text_to_find)
Where:
- cell_reference: The cell or range of cells you want to search within.
- text_to_find: The text or value you are looking for.
For instance, the formula =CONTAINS(A1, "Apple")
will return TRUE if the text "Apple" is found in cell A1, and FALSE otherwise.
Combining IF and CONTAINS: The IF CONTAINS Formula

By combining the IF and CONTAINS functions, you can create powerful formulas that perform actions based on the presence or absence of specific text or values. The basic syntax for the IF CONTAINS formula is as follows:
=IF(CONTAINS(cell_reference, text_to_find), value_if_true, value_if_false)
Let's break down the components:
- CONTAINS(cell_reference, text_to_find): This part of the formula checks if the specified text is present in the given cell or range.
- value_if_true: The value or action to be taken if the text is found.
- value_if_false: The value or action to be taken if the text is not found.
For example, the formula =IF(CONTAINS(A1, "Apple"), "Fruits", "Vegetables")
will return "Fruits" if the text "Apple" is found in cell A1, and "Vegetables" otherwise.
Step-by-Step Guide: Creating an IF CONTAINS Formula

Now, let's walk through the process of creating an IF CONTAINS formula in Excel. We'll use a simple example to categorize a list of fruits based on whether they contain the word "apple" in their names.
-
Open your Excel workbook and navigate to the worksheet where you have your data.
-
In a blank cell, enter the following formula:
=IF(CONTAINS(A2, "apple"), "Contains Apple", "Does not contain Apple")
Replace
A2
with the cell reference of the first fruit name in your list. -
Press Enter to see the result. In this case, if the fruit name contains the word "apple," the formula will return "Contains Apple." Otherwise, it will return "Does not contain Apple."
-
To apply this formula to the entire list of fruits, select the cell containing the formula and drag the fill handle down to the last row of your data.
Now, you have a categorized list of fruits based on the presence of the word "apple" in their names.
Examples and Applications

The IF CONTAINS formula has numerous applications in data analysis and automation. Here are a few examples to inspire you:
1. Categorizing Products
Suppose you have a list of products, and you want to categorize them based on whether they contain the word "organic" in their descriptions. You can use the IF CONTAINS formula to automatically classify them into "Organic" and "Non-Organic" categories.
2. Flagging Duplicate Values
If you have a large dataset and want to flag duplicate values, you can use the IF CONTAINS formula to compare each value with the range of values in the dataset. If a value is found more than once, the formula can return a flag or a specific text to indicate duplication.
3. Automating Email Responses
In customer service or support systems, you can use the IF CONTAINS formula to automatically respond to emails based on the content of the subject line or body. For example, if an email contains the word "urgent," you can set up a formula to send an automated response acknowledging the urgency and assigning a high priority to the ticket.
Tips and Best Practices

When working with the IF CONTAINS formula, keep these tips in mind to optimize your experience:
-
Case Sensitivity: By default, the CONTAINS function is case-insensitive, meaning it will find "apple" even if the text is "Apple" or "APPLE." If you need case-sensitive matching, consider using the EXACT function instead of CONTAINS.
-
Wildcards: You can use wildcards like
*
and?
within the CONTAINS function to perform more flexible searches. For example,CONTAINS(A1, "*apple*")
will find "apple," "apples," and "red apple." -
Error Handling: Be mindful of potential errors when using the IF CONTAINS formula. If the CONTAINS function returns an error due to an invalid cell reference or text, the entire formula will also return an error. Ensure that your cell references and text inputs are valid.
Conclusion

The IF CONTAINS formula in Excel is a versatile tool that allows you to automate tasks, categorize data, and make decisions based on the presence or absence of specific text or values. By combining the IF and CONTAINS functions, you can create powerful formulas to streamline your data analysis and workflow. Experiment with different applications and adapt the formula to suit your specific needs. With practice, you'll become an expert in harnessing the power of the IF CONTAINS formula in Excel.
What is the difference between the CONTAINS function and the SEARCH function in Excel?
+The CONTAINS function returns TRUE or FALSE based on whether the specified text is found within a cell or range. On the other hand, the SEARCH function returns the position of the first occurrence of the specified text within a cell or range. The SEARCH function is more flexible and can be used with wildcards, making it suitable for more complex text searches.
Can I use the IF CONTAINS formula to perform calculations based on the presence of specific text?
+Yes, you can! The IF CONTAINS formula can be used to perform calculations or take actions based on the presence of specific text. For example, you can set up a formula that calculates a discount based on whether a product name contains the word “sale.”
Are there any alternatives to the CONTAINS function for text searching in Excel?
+Yes, there are several alternatives. Apart from the SEARCH function mentioned earlier, you can also use the FIND function, which is similar to SEARCH but case-sensitive. Additionally, the EXACT function can be used to compare two text strings and return TRUE if they are exactly the same, including case and formatting.