Written by Allen Wyatt (last updated August 6, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021
At his office, Wally is responsible for making sure that aircraft are maintained on a set scheduled based on the number of hours they have accrued in flight time. He uses Excel to track the amount of flight time for each aircraft. In cell F1 he has the "threshold" for when maintenance should occur, as a number of hours. Wally needs a way to make the cell containing each aircraft's total flight time turn red once that total is within 5 hours of the threshold in F1.
This can be easily handled with conditional formatting, with one proviso: the accrued flight hours need to be stored as numeric values, not as date or time values.
You can test whether this condition is met by simply changing the formatting of one of the cells containing accrued flight hours. For example, let's say that cell D2 shows 3.5 accrued flight hours. Select that cell and change its format to General. If the resulting display still shows 3.5, then you are fine. If it shows something different, there is a good chance that the cell doesn't contain the numeric number of flight hours. In that case, you'll need to do a conversion on the hours to get what you need:
=ROUND(MOD(D2,1)*24,2)
This formula strips off the portion of the value that is before the decimal point (this portion represents a date and we are only interested in the time) and then rounds it to two decimal places.
Once you have the accrued flight time expressed as a numeric value, you can then create the conditional formatting rule you need:
If you prefer to not use a conditional formatting rule (perhaps you already have some other such rules in play), you could also rely on a custom format to do the formatting. In this approach, though, you don't rely on what is in cell F1. Instead, you need to "hard wire" the trigger value into the format. For instance, if your threshold in F1 is 500 hours, then your trigger value would be 495 hours. Follow these steps:
Figure 1. The Number tab of the Format Cells dialog box.
Now any accrued hours that are less than 495 will display normally and anything over that will show up in red. This approach does have some benefits (custom formats don't get messed up like conditional formatting sometimes does), but it means that if your trigger value changes at some point in the future, you'll need to modify the custom format directly.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13496) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
Conditional formatting is a great tool for changing the format of cells based on whether certain conditions (rules) are ...
Discover MoreConditional formatting is a great feature in Excel. Here's how you can copy conditional formats from one cell to another ...
Discover MoreThe Conditional Formatting capabilities of Excel are powerful. This tip shows how you can use a simple approach to ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-08-07 17:16:25
Dave Bonin
FWIW, I greatly prefer to use custom number formats (Allen's second method) over conditional formatting.
Why?
Because custom number formats are much more stable than conditional formats and do not suffer from the latter's "breeding problem".
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments