Skip to Content

How to change a cell color based on text in excel dynamically?

Excel has many useful features for formatting cells based on their contents. One handy trick is the ability to automatically change the color of cells based on the text or value they contain. This can help highlight certain cells or make your spreadsheets easier to read. In this post, I’ll explain how to dynamically color cells using Excel’s conditional formatting feature.

What is Conditional Formatting

Conditional formatting allows you to apply formats like colors, icons, data bars, and more to cells based on the value or text they contain. For example, you may want all negative numbers to be colored red or all cells containing the text “Complete” to turn green. Conditional formatting makes it easy to visualize this kind of data at a glance.

To access the conditional formatting options, select the cells you want to format, go to the Home tab, and click Conditional Formatting. This will open a menu with many formatting options based on cell values, top/bottom rules, data bars, color scales, icons, and more.

Conditional Formatting Options
Highlight Cell Rules
Top/Bottom Rules
Data Bars
Color Scales
Icons
New Rule

For this example of coloring cells by text, we’ll use the New Rule option to create a custom conditional formatting rule.

Using the New Formatting Rule Dialog

Here are the steps to create a new conditional formatting rule based on text:

  1. Select the cells you want to format.
  2. On the Home tab, click Conditional Formatting > New Rule.
  3. In the New Formatting Rule dialog box, select the Format only cells that contain option.
  4. Set the drop down to Cell Value and the operator to Equals.
  5. Type in the text or value you want to trigger the formatting.
  6. Click the Format button and select the Fill tab.
  7. Choose the color to highlight the cells.
  8. Click OK to complete the rule.

This will create a rule that looks for the specified text or value, and colors any matching cells. You can repeat these steps to add multiple rules for different text values.

Example: Color Code Status Values

Here is an example of using conditional formatting rules to color code order status values in an Excel table:

Order Number Status
1001 Pending
1002 Processed
1003 Shipped
1004 Cancelled

To highlight the Pending orders in yellow, Processed in green, Shipped in blue, and Cancelled in red, here are the conditional formatting rules to use:

Value Color
Pending Yellow
Processed Green
Shipped Blue
Cancelled Red

The end result will make it very easy to visualize order status at a glance!

Additional Tips

Here are some additional tips for dynamically coloring cells based on text in Excel:

  • The conditional formatting rules apply to the selected cells, so make sure you select all cells you want included before creating the rule.
  • You can enter wildcards like “*” and “?” in the formatting rule when you want to match partial text values.
  • The rules you create can be applied to other cells by selecting the new cells and clicking the Manage Rules button to re-apply.
  • Use the Stop If True option to stop checking other rules if a match occurs. This can improve performance on large data sets.
  • To remove a formatting rule, use the Manage Rules menu and delete the unneeded rules.

Using Formulas for More Complex Rules

In some cases, you may need more complex logic to conditionally format cells based on multiple criteria or values. For these scenarios, you can use the “Use a formula to determine which cells to format” option in the New Formatting Rule dialog.

For example, let’s say you want to color code product margins in a table by creating these rules:

  • Margin > 30% = Green
  • Margin 20-30% = Yellow
  • Margin

Here is the formula you could use:

=IF(C2>0.3,”Green”,IF(AND(C2>=0.2,C2Where C2 contains the actual margin percentage value. This checks the value against the rule thresholds and outputs a text value of Green, Yellow, or Red which can be used to color the cells.

Using formulas opens up many possibilities for more advanced conditional formatting. You can reference other cells, use complex logic with AND/OR/NOT statements, leverage Excel functions, and more.

Conclusion

Conditional formatting based on cell text or values is a very useful Excel feature. It allows you to visualize data at a glance, highlight important information, and make your spreadsheets easier for others to interpret. The next time you have a dataset with text or numeric values to categorize, consider using conditional formatting to color code the cells dynamically based on their contents.

With the New Formatting Rule dialog box, you can easily create custom rules to color cells based on specific text, values, or formulas. Some clever use of wildcard characters, rule precedence, and formulas allows for quite advanced conditional formatting solutions. Take your Excel skills to the next level by mastering the use of conditional formatting in your workbooks.