Highlighting After-Hours Times

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


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 2021.

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

Automatically Protecting After Input

Do you want user-entered data to be immediately protected so that it cannot be changed? This can be done relatively ...

Discover More

Undoing the Effects of a Sort

Have you ever put a lot of data into a worksheet, sorted that data, and then realized you shouldn't have done so? It is ...

Discover More

Problem with Missing Context Menu Option

When you right-click a cell, does it seem that the Context menu is missing an item or two? Here's how to get those items ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 365 applications with VBA programming. Written in clear terms and understandable language, the book includes systematic tutorials and contains both intermediate and advanced content for experienced VB developers. Designed to be comprehensive, the book addresses not just one Office application, but the entire Office suite. Check out Mastering VBA for Microsoft Office 365 today!

More ExcelTips (ribbon)

Highlighting Greater Than Average Dry Durations

If you need to find whether the duration between two dates is greater than the average of all durations, you'll find the ...

Discover More

Conditionally Formatting Non-Integers

The conditional formatting capabilities of Excel are very helpful when you want to call attention to different values ...

Discover More

Converting Conditional Formatting to Regular Formatting

Conditional formatting allows you to change how information is displayed based on rules you define. What if you want to ...

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 5 - 3?

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.