Excel Conditional Formatting: Apply Text-Based Rules

In the vast world of data management, Excel stands as a powerhouse, offering a myriad of features to streamline tasks and enhance productivity. One such feature is conditional formatting, which allows you to apply specific formatting to cells based on their values. Today, we're delving into a specific aspect of this: using conditional formatting with a formula to check if a cell contains text.

Excel Conditional Formatting If a Cell Contains Any Text
Excel Conditional Formatting If a Cell Contains Any Text

Before we dive into the nitty-gritty, let's ensure we're on the same page. Conditional formatting is a tool that lets you apply different formatting to cells based on their content. This could be anything from changing the font color to highlighting the cell, or even displaying an icon. In this context, we're interested in using a formula to check if a cell contains a specific text string.

Excel Conditional Formatting Based on Another Cell Tutorial
Excel Conditional Formatting Based on Another Cell Tutorial

Understanding the IF Function

At the heart of our conditional formatting formula lies the IF function. This function allows you to perform different actions based on a condition. In its simplest form, the IF function has the following syntax: IF(logical_test, value_if_true, value_if_false).

a screenshot of the format dialog box with an arrow pointing to the text area
a screenshot of the format dialog box with an arrow pointing to the text area

The logical_test is the condition that Excel checks. If this condition is true, Excel returns the value_if_true. If the condition is false, Excel returns the value_if_false. In our case, we're interested in the logical_test that checks if a cell contains a specific text string.

Using the IF Function with Text

Excel Conditional Formatting with Formula If Cell Contains Text
Excel Conditional Formatting with Formula If Cell Contains Text

To check if a cell contains text, we can use the IF function in conjunction with the ISNUMBER and SEARCH functions. The SEARCH function returns the position of the first occurrence of the search string within the text string. If the search string is not found, SEARCH returns an error (#VALUE!). The ISNUMBER function, on the other hand, checks if a value is a number.

So, our logical_test will be: ISNUMBER(SEARCH("text", A1)). Here, "text" is the text string we're looking for, and A1 is the cell we're checking. If the text string is found in the cell, SEARCH will return a number, which ISNUMBER will recognize as true. If the text string is not found, SEARCH will return an error, which ISNUMBER will recognize as false.

Applying Conditional Formatting

Top 21 Excel Formulas
Top 21 Excel Formulas

Now that we have our formula, we can apply conditional formatting to our cells. Here's how:

  1. Select the cells you want to apply the formatting to.
  2. Click on the 'Home' tab in the ribbon.
  3. In the 'Styles' group, click on the 'Conditional Formatting' button.
  4. Select 'New Rule...' from the dropdown menu.
  5. In the 'New Formatting Rule' dialog box, select 'Use a formula to determine which cells to format'.
  6. In the 'Format values where this formula is true:' box, enter your formula (e.g., =ISNUMBER(SEARCH("text", A1))).
  7. Click on the 'Format...' button to choose the formatting you want to apply.
  8. Click 'OK' to close the 'Format Cells' dialog box.
  9. Click 'OK' again to close the 'New Formatting Rule' dialog box.

The selected cells will now be formatted based on whether they contain the specified text string.

Excel Conditional Formatting
Excel Conditional Formatting

Advanced Text Checks

Sometimes, you might want to check for more complex text conditions. For instance, you might want to check if a cell contains a specific text string, but only if it's in a certain position or surrounded by other text.

the basic excel formats for each type of text, including numbers and letters that are in
the basic excel formats for each type of text, including numbers and letters that are in
Complete Excel Formula Cheat Sheet | Excel Functions, Shortcuts & Tips for Students
Complete Excel Formula Cheat Sheet | Excel Functions, Shortcuts & Tips for Students
Conditional Formatting in Excel
Conditional Formatting in Excel
Conditional Formatting on Text that Contains Multiple Words in Excel
Conditional Formatting on Text that Contains Multiple Words in Excel
3 Crazy Microsoft Excel Formulas That Are Extremely Useful
3 Crazy Microsoft Excel Formulas That Are Extremely Useful
Excel Formulas: Basic to Advanced
Excel Formulas: Basic to Advanced
advanced conditional formatting in excel
advanced conditional formatting in excel
How to Copy Conditional Formatting to Another Cell in Excel
How to Copy Conditional Formatting to Another Cell in Excel
How to Do Conditional Formatting Based on Another Cell in Excel (6 Easy Ways) - ExcelDemy
How to Do Conditional Formatting Based on Another Cell in Excel (6 Easy Ways) - ExcelDemy
How (and why) to use conditional formatting in Excel
How (and why) to use conditional formatting in Excel
a poster with instructions on how to use excel
a poster with instructions on how to use excel
Excel conditional formatting for dates & time: formulas and rules
Excel conditional formatting for dates & time: formulas and rules
Apply Conditional Formatting on Multiple Texts in Excel
Apply Conditional Formatting on Multiple Texts in Excel
Change Cell Colour using Conditional Formatting
Change Cell Colour using Conditional Formatting
Excel Count Cells with Text - Text and Values, Count any Text, Occurrence of specific Text
Excel Count Cells with Text - Text and Values, Count any Text, Occurrence of specific Text
the top 2 excel formulas are shown in this poster, and it is also available for
the top 2 excel formulas are shown in this poster, and it is also available for
Excel Conditional Formatting tutorial with examples
Excel Conditional Formatting tutorial with examples
Excel Formula Guide for Office & MIS Work
Excel Formula Guide for Office & MIS Work
Excel Conditional Formatting Tutorial
Excel Conditional Formatting Tutorial
5 Handy Excel Tricks for Conditional Formatting Every Analyst Should Know
5 Handy Excel Tricks for Conditional Formatting Every Analyst Should Know

For such cases, you can use the MID function to extract a specific portion of the text string, and then check if that portion matches your search string. For example, to check if the first three characters of a cell are "ABC", you could use the formula: =ISNUMBER(SEARCH("ABC", MID(A1, 1, 3))).

Case Sensitivity

By default, the SEARCH function is case-sensitive. This means it will treat "Text" and "text" as two different strings. If you want to perform a case-insensitive search, you can use the UPPER or LOWER function to convert both the search string and the text string to the same case before performing the search.

For example, to check if a cell contains the text string "text", regardless of its case, you could use the formula: =ISNUMBER(SEARCH(UPPER("text"), UPPER(A1))).

And there you have it! You're now equipped to use conditional formatting with a formula to check if a cell contains text in Excel. Whether you're highlighting important data or flagging errors, this tool can significantly enhance your data management capabilities. So, go forth and format!