Formatting Issues

Excel Conditional Formatting for Times Inside or Outside a Range

Huma Ashraf ChHuma Ashraf Ch Nov 25, 2026 870 views

Question details

Apply different colors to times inside and outside a specified range.

Conditional Formatting for Times Inside or Outside a Range in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet contains times that should be colored purple from 3:10 PM through 3:25 PM and brown outside that range.
Observed behavior
Times at or between the two endpoints should appear purple; earlier and later times should appear brown.
Before you start

Make sure the cells contain actual Excel time values rather than text, and that they do not include a date. Identify the first cell in the range you want to format; the example below uses F7:F14.

Solution 1Recommended

Create Two Formula-Based Conditional Formatting Rules in Excel

Use one rule for the inclusive time range and another for times outside it.

1
Select the time cells

Select F7:F14, or select your own range and replace F7 in both formulas with its top-left cell.

2
Create the inside-range rule

Go to Home > Conditional Formatting > New Rule, choose Use a formula to determine which cells to format, and enter =AND(F7>=TIME(15,10,0),F7<=TIME(15,25,0)).

3
Set the purple format

Click Format, choose a purple fill, and click OK to save the rule.

4
Create the outside-range rule

With the same cells selected, go to Home > Conditional Formatting > New Rule, choose the formula option, and enter =OR(F7<TIME(15,10,0),F7>TIME(15,25,0)).

5
Set the brown format

Click Format, choose a brown fill, and click OK to save the rule.

Create Two Formula-Based Conditional Formatting Rules in Excel
Check the formulas and cell values: Enter each formula with its leading equals sign and without surrounding quotation marks. The endpoints are included in the purple range. Blank cells may be colored brown, so select populated time cells or add a nonblank condition if needed.
Format times in WPS Spreadsheet

Color Time Ranges with WPS Spreadsheet

Use formula-based conditional formatting in WPS Spreadsheet to assign different colors to times inside and outside the selected range.

  1. 1. Open and select the cells: Open the workbook in WPS Spreadsheet and select F7:F14, or your own range of time cells.
  2. 2. Add the inside-range rule: On the Home tab, open Conditional Formatting > New Rule, choose the formula-based rule option, and enter =AND(F7>=TIME(15,10,0),F7<=TIME(15,25,0)). Replace F7 with your selection's top-left cell if needed.
  3. 3. Choose purple: Open the rule's Format settings, select a purple fill, and save the rule.
  4. 4. Add the outside-range rule: Create another formula-based rule for the same selection using =OR(F7<TIME(15,10,0),F7>TIME(15,25,0)), and choose a brown fill in Format.
Highlight an inclusive time range with formula-based rulesChoose separate fill colors for inside and outside timesOpen and save Microsoft Excel XLSX filesWork with a familiar spreadsheet interface
microsoft office alternative - wps office

Frequently Asked Questions

Are 3:10 PM and 3:25 PM included in the purple range?

Yes. The inside-range formula uses >= and <=, so both endpoints are included.

How do I apply the formulas to a different range?

Select your range before creating the rules and replace F7 in both formulas with the range's top-left cell. Leave the reference relative so it adjusts for each cell.

Why are blank cells turning brown?

Excel can evaluate a blank cell as zero in the outside-range formula. To exclude blanks, use =AND(F7<>"",OR(F7<TIME(15,10,0),F7>TIME(15,25,0))) for the brown rule.

Will these rules work if a cell contains a date and time?

Not as written: a date adds a whole-number component to the value. Use =MOD(F7,1) in place of F7 in the comparisons to evaluate the time portion, and account for blank cells separately if needed.

Why is my conditional formatting formula not working?

In Home > Conditional Formatting > Manage Rules, check that the formula starts with =, has no surrounding quotation marks, and refers to the top-left cell of the applied range. Also confirm the cells contain real time values rather than text.