Conditional Formatting in Excel

Conditional Formatting in Excel is a technique where we format cells in a worksheet based on certain conditions, conditional formatting option is available in the styles section of the Home tab, there are various conditions provided by excel to use formatting on cells or a user can create a new rule for conditional formatting using a formula.

Conditional Formatting in Excel (with Formulas)

Conditional formatting is a feature in an excel spreadsheet that allows you to apply specific formatting to cells/range that meet the specified criteria/condition. The mostly formatting rule is used as color-based formatting to highlight or distinguish among data and information stored in an excel sheet.

How to apply conditional formatting in excel?

It will highlight the Cell A1 with red color if the value in A1 cell will be 1.

  1. Start Excel, and then open a new Excel worksheet.

  2. In the Excel worksheet, select any cell A1.

    conditional formatting 1

  3. Click Conditional Formatting in Excel Styles group, and then click New Rule.

    conditional formatting 1-1

  4. Click Use a formula to determine which cells to format under Select a Rule Type.

    conditional formatting 1-2

  5. Click inside the Format values where this formula is true. Then, select the cell that you want to use for the conditional formatting in excel.

    conditional formatting 1-3

  6. Modify the value in step 6 to be =$A$1=1.

    conditional formatting 1-4

  7. Click Format.

    conditional formatting 1-5

  8. In the Format Cells dialogue box, click the Fill.

    conditional formatting 1-6

  9. Click the color “red,” and then click OK.

    conditional formatting 1-7

  10. In the New Formatting Rule dialogue box, click OK.

    conditional formatting 1-8

  11. In cell A1, type 1, and then press the ENTER key.

  12. Verify that the color of the cell B1 changed to red.

    conditional formatting 1-9

  13. Close the Excel worksheet.

How to use the Conditional Formatting Excel Rule?

Let us understand working with simple examples.

Conditional Formatting Example #1

Highlight the data that is greater than 30.

Choose Highlight Cells Rules > Greater Than

conditional formatting example 1

Enter the number.

conditional formatting example 1-1

Below is the result:

conditional formatting example 1-2

Example #2

Highlight the data with duplicate valuesHighlight The Data With Duplicate ValuesHighlight Cells Rule, which is available under Conditional Formatting under the Home menu tab, can be used to highlight duplicate values in the selected dataset, whether it is a column or row of a more.

Choose Highlight Cells Rules > Duplicate Values

conditional formatting example 2

Click on Duplicate and OK

conditional formatting example 2-1

The result will be:

conditional formatting example 2-2

Example #3

Apart from simple rules like greater than and duplicates, there are others like “A Date Occurring…”. This condition is based on dates. Many conditions will have sub-conditions. This is one such example.

Here, we will select all the dates and apply the conditional format.

conditional formatting example 3

Choose Highlight Cells Rules > A Date Occurring.

conditional formatting example 3-1

Within this dialogue box, there are many date – related options available.

conditional formatting example 3-2

We will use ‘This Week’ as we want to highlight all the dates that fall in the current week. Likewise, you can use any other setting, as needed.

conditional formatting example 3-3

So the result will be:

conditional formatting example 3-4

Example #4

Here we have a given data set of date and count, and we have to apply the multiple formatting rules.

conditional formatting example 4

First, we highlight the cell value that is between 31 and 43.

conditional formatting example 4-1
conditional formatting example 4-2

Select color yellow fill with Dark yellow text.

conditional formatting example 4-3

The result will be:

conditional formatting example 4-4

And then, apply another formatting on cells that have less than 0 value with the color of Light Red Fill with Dark Red Text.

conditional formatting example 4-5

And the Final Result will look like this:

conditional formatting example 4-6

Example #5

You can use Data bars, color scale, and icon sets in excelIcon Sets In ExcelExcel icon sets are part of the conditional formatting graphics for numerical data sets. They help design the numbers more beautifully Directional, Shapes, Indicator, and Ratings are the many types of icon sets. read more for conditional formatting in ExcelFormatting In ExcelFormatting is a useful feature in Excel that allows you to change the appearance of the data in a worksheet. Formatting can be done in a variety of ways. For example, we can use the styles and format tab on the home tab to change the font of a cell or a more.

First, we will use Data bars in excelData Bars In ExcelData bars are a type of conditional formatting option in Excel that are used to highlight cells or data ranges in a worksheet based on certain more.

Go to Data Bars > Select Blue Data Bar.

conditional formatting example 5

Now, we will use Color Scales.

Go to Color Scales > Select any Color you want to.

conditional formatting example 5-1

Now, we will use the Icon Sets.

Go to Icon Sets > Select any icon you want to.

conditional formatting example 5-2

Finally, the table will look like this

conditional formatting example 5-3

Conditional Formatting can be used in VBA

We can apply the formatting rule using VBAApply The Formatting Rule Using VBAConditional formatting is also possible in Excel VBA programming by using the ‘Format Conditions Collection' macro/procedure. A conditional format is one that is applied only to cells that meet certain criteria, such as values above a certain threshold, positive or negative values, or values with a specific formula, and so more; here is the example as follows:

Sub Example()
With ThisWorkbookWith ThisWorkbookVBA ThisWorkbook refers to the workbook on which the users currently write the code to execute all of the tasks in the current workbook. In this, it doesn't matter which workbook is active and only requires the reference to the workbook, where the users write the more.Worksheets(1).Range(“B1”)
.FormatConditions.Add Type:=xlExpression, _
.FormatConditions(1).Interior.ColorIndex = 46
End With
End Sub

You can download this Conditional Formatting template here – Conditional Formatting Excel Template

Recommended Articles

This has been a guide to Conditional Formatting in Excel. Here we discuss how to use the Conditional Formatting formula along with excel example and downloadable excel templates. You may also look at these useful functions in excel –

  • 35+ Courses
  • 120+ Hours
  • Full Lifetime Access
  • Certificate of Completion

Reader Interactions


  1. sandeepkothari says

    Great stuff on cond. formtg.

    • Dheeraj Vaidya says

      Thanks for your kind words!