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

Saving a Workbook in a Macro

Does your macro need to make sure that the workbook being processed is saved to disk? You can add the saving capability ...

Discover More

Recovered Document becomes Default

Word has a feature called AutoRecover that helps you when Word or Windows crashes. If your Normal template gets messed up ...

Discover More

Using Optional Hyphens

Adding hyphens to your document can affect the way in which Word wraps text from one line to the next. Optional hyphens, ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

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

Shading Based on Odds and Evens

You can use conditional formatting to add shading to various cells in your worksheet. This tip shows how you can shade ...

Discover More

Diagonal Borders in a Conditional Format

Conditional formatting is a great tool for changing how your data looks based on the data itself. Excel won't allow you ...

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 two more than 7?

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.