Excel中如图将B列日期超过3天变红色,当外协加工那一列填写后B列恢复正常,怎么做,请详细下,谢谢

2025-05-20 05:37:16
推荐回答(4个)
回答1:

选中B列,开始--样式--条件格式,“新建规则”,用公式:
=AND(TODAY()-B1>3,E1="")
设置格式:填充红色。

回答2:

用Excel VBA来做比较省事,有两种方法,一,手动刷新法:按Alt+F11打开VBE窗口,新建模块,写入以下代码:

本代码在B列里的数据不限,几万条数据本代码通用,使用的时候可以用Alt+F8键。

Sub bij()

Dim i, t

For i = 2 To Cells(Rows.Count, 2).End(xlUp).Row

If Cells(i, 5) = "" And (Year(Date) - Year(Cells(i, 2)) > 0 Or Month(Date) - Month(Cells(i, 2)) > 0 Or Day(Date) - Day(Cells(i, 2)) > 3) Then

Cells(i, 2).Interior.ColorIndex = 3

Else

Cells(i, 2).Interior.ColorIndex = Clear

End If

If Cells(i, 5) = "" And Cells(i, 2) = "" Then Cells(i, 2).Interior.ColorIndex = Clear

Next i

End Sub

第二种,每次打开Excel表的时候刷新:在VBE窗口的ThisWorkbook窗口里写入以下代码:

Private Sub Workbook_Open()

Dim i, t

For i = 2 To Cells(Rows.Count, 2).End(xlUp).Row

If Cells(i, 5) = "" And (Year(Date) - Year(Cells(i, 2)) > 0 Or Month(Date) - Month(Cells(i, 2)) > 0 Or Day(Date) - Day(Cells(i, 2)) > 3) Then

Cells(i, 2).Interior.ColorIndex = 3

Else

Cells(i, 2).Interior.ColorIndex = Clear

End If

If Cells(i, 5) = "" And Cells(i, 2) = "" Then Cells(i, 2).Interior.ColorIndex = Clear

Next i

End Sub

这样每次打开工作薄的时候就会更新!注意!保存的时候要保存成带宏的格式(.xlsm)。如果打开Excel用不了,可能你的宏是禁用的,设置方法如下:依次打开,文件,Excel选项,信任中心,宏设置,将安全级别调到最低就可以了。

回答3:

选中B列(但是不要选中B1单元格),开始-样式-条件格式,点击“新建规则”,
用公式:=AND(B2<>"", DATEDIF(B2,TODAY(),"d")>3, E2="")

回答4:

“B列日期超过3天”指B列日期超过2100年12月31日三天吗?!