Highlighting After-Hours Times

Written by Allen Wyatt (last updated May 1, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


Tom has a worksheet that contains start times and end times for jobs. All times are entered in 24-hour notation. He needs a way to highlight any time that is after 17:00 (5:00 pm) or before 08:00 (8:00 am).

This is precisely the situation in which Conditional Formatting really shines. How you put together the formatting rules, though, depends on how your data is set up and what, exactly, you want to highlight.

Let's say that Tom's data is in columns A and B. In column A he enters a start time and in column B he enters the end time. If Tom wants to highlight only those start times that are in the after-hours range, he could follow these steps:

  1. Make sure all the cells in column A are formatted as times. This is important because it means that Excel will evaluate your comparisons in the Conditional Formatting rule properly.
  2. Select all the cells in column A that might, at some point, contain a start time. You can, if desired, select all of column A, but that might be overkill.
  3. Make sure the Home tab of the ribbon is displayed.
  4. Click the Conditional Formatting option in the Styles group. Excel displays a palette of options related to conditional formatting.
  5. Choose New Rule. Excel displays the New Formatting Rule dialog box.
  6. In the Select a Rule Type list, choose Format Only Cells That Contain. (See Figure 1.)
  7. Figure 1. The New Formatting Rule dialog box.

  8. Make sure the first drop-down list in the Edit the Rule Description area is "Cell Value." (This should be the default.)
  9. Make sure the second drop-down list is "Not Between." Two boxes appear to the right of the drop-down list where you can enter an earlier time and a later time.
  10. In the earlier time box, enter 8:00.
  11. In the later time box, enter 17:00.
  12. Use the format controls to set your highlighting any way you desire.
  13. Click OK. The Conditional Formatting Rules Manager dialog box appears with your newly defined condition in it.
  14. Close the Rules Manager dialog box.

If you wanted to highlight either start or end times that are in the after-hours range, all you have to do is to select both columns A and B in step 2.

When you are specifying your formatting (step 11), I suggest that you don't use a format that fills the interior of the cell with a color. This is because if the cell is blank, it will always meet the test you defined in steps 7-10. (A blank cell would be considered a time of 00:00, which is midnight and therefore after hours.)

If you want a Conditional Format that will check for the blank cells, then you can follow these steps:

  1. Make sure all the cells in column A are formatted as times. This is important because it means that Excel will evaluate your comparisons in the Conditional Formatting rule properly.
  2. Select all the cells in column A that might, at some point, contain a start time. You can, if desired, select all of column A, but that might be overkill.
  3. Make sure the Home tab of the ribbon is displayed.
  4. Click the Conditional Formatting option in the Styles group. Excel displays a palette of options related to conditional formatting.
  5. Choose New Rule. Excel displays the New Formatting Rule dialog box.
  6. In the Select a Rule Type area at the top of the dialog box, choose Use a Formula to Determine Which Cells to Format.
  7. In the Format Values Where This Formula Is True box, enter "=IF(LEN(A1)>0,OR(A1<8/24,A1>17/24),FALSE)" (without the quote marks).
  8. Use the format controls to set your highlighting any way you desire.
  9. Click OK. The Conditional Formatting Rules Manager dialog box appears with your newly defined condition in it.
  10. Close the Rules Manager dialog box.

The formula in step 7 assumes that the range of cells you selected in step 2 has cell A1 at the upper-left corner of the range. If your range has a different cell in that position, make sure you adjust the formula in step 7 to reflect that difference.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13853) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Printing a List of Custom Styles

You can add any number of styles to your document in order to define how you want your text to appear. If you later want ...

Discover More

Running a Macro in a Number of Workbooks

Got a macro that you need to run on each of a number of workbooks? Excel provides a number of ways to go about this task, ...

Discover More

Changing to a Non-US Date Format

Do you want to specify your months and days differently when displaying dates in your worksheets? This tip looks at how ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Returning a Value Based on Text Color

Conditional formatting rules can be used to adjust the way in which information is displayed in Excel, such as the text ...

Discover More

Deleting Conditional Formatting

After you've applied a conditional format to a cell, you may have a need to later delete that format so that the cell is ...

Discover More

Controlling Data Entry in a Cell

Sometimes you want whatever is displayed in one cell to control what is displayed in a different cell. This tip looks at ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 - 5?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.