简体   繁体   English

基于另一个单元格中的日期的条件格式

[英]Conditional formatting based on date in another cell

I have text in cell A1 that I want to apply conditional formatting to based on the dates in cells A2:A5.我在单元格 A1 中有文本,我想根据单元格 A2:A5 中的日期应用条件格式。 That is if a date in A2:A5 is older than today I want A1 to be filled in red.也就是说,如果 A2:A5 中的日期比今天早,我希望 A1 填充为红色。 If the date in A2:A5 is less than 30 days from today I want A1 to be orange.如果 A2:A5 中的日期距今天不到 30 天,我希望 A1 为橙色。 I have tried various formulas and just cant seem to get it to work.我尝试了各种公式,但似乎无法让它发挥作用。 Appreciate any help.感谢任何帮助。 Thanks谢谢

You need to use conditional formatting (button in the home ribbon).您需要使用条件格式(主页功能区中的按钮)。 Choose new rule and click 'Use a formula'.选择新规则并单击“使用公式”。 Enter the formula you want and click format and select the fill colour you want it to be.输入您想要的公式,然后单击格式并选择您想要的填充颜色。 Click OK.单击确定。 You can do this multiple times with different colours and formulas.您可以使用不同的颜色和公式多次执行此操作。

So something like this would make A1 change if A2 was within 30 days:因此,如果 A2 在 30 天内,这样的事情会使 A1 发生变化:

=$A$2<($A$1-30)=TRUE

But what colour would A1 be if the dates in cells A2:A5 are a variety of dates?但是如果单元格 A2:A5 中的日期是各种日期,A1 会是什么颜色? Eg.例如。 some are less than 30 days some more?有些少于 30 天,有些更多? The technique above is easy when comparing A1 to one cell.将 A1 与一个单元格进行比较时,上述技术很容易。 I am not sure you have thought about this or you just have not explained yourself properly.我不确定您是否考虑过这一点,或者您只是没有正确解释自己。

EDIT:编辑:

If A1 is not a static date and you want formatting based on the current timeframe (eg B1 falls within 30 days) then use the Date Occurring feature.如果 A1 不是静态日期并且您希望根据当前时间范围进行格式化(例如 B1 落在 30 天内),则使用发生日期功能。 Examples of how you can use if below.下面是如何使用 if 的示例。 So you are going to need 12 of these to cover B1:G1 with 30 days for orange and one day for red.因此,您将需要其中的 12 个来覆盖 B1:G1,其中橙色为 30 天,红色为 1 天。

发生日期 X内的日期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM