【发布时间】:2017-10-18 18:57:45
【问题描述】:
我有 VBA 代码,可以将用户输入的日期与当前日期进行比较,并用适当的颜色填充背景。一切正常。
现在我需要让系统检查所选行 F 列中的单元格是否不为空 我需要为 D 列着色, E,F 为灰色。
代码:
Private Sub CommandButton1_Click()
Dim i As Integer
For i = Range("C5000").End(xlUp).Row To 2 Step -1 'Range upto 5000, chnge this as per your requirment'
If IsEmpty(Cells(i, 3)) Then
Cells(i, 3).Interior.Color = xlNone
ElseIf (VBA.CDate(Cells(i, 3)) - VBA.Date()) < 0 Then
Cells(i, 3).Interior.Color = vbGreen
ElseIf (VBA.CDate(Cells(i, 3)) - VBA.Date()) = 0 Then
Cells(i, 3).Interior.Color = vbYellow
ElseIf (VBA.CDate(Cells(i, 3)) - VBA.Date()) >= 1 And (VBA.CDate(Cells(i, 3)) - VBA.Date()) <= 4 Then
Cells(i, 3).Interior.Color = vbRed
ElseIf (VBA.CDate(Cells(i, 3)) - VBA.Date()) >= 5 And (VBA.CDate(Cells(i, 3)) - VBA.Date()) <= 10 Then
Cells(i, 3).Interior.Color = vbCyan
Else
Cells(i, 3).Interior.ColorIndex = xlNone
End If
Next
End Sub
我将不胜感激任何帮助
【问题讨论】:
-
使用条件格式
-
@Rosetta 不,我需要在我的代码中添加它
-
if cells(i,6) <> "" then cells(i,3).entirerow.interior.color = vbRed... 这能解决您的问题吗? -
@Dany7elo 在下面查看我的答案和代码
标签: excel if-statement is-empty vba