如何应用填充颜色取决于使用VBA的单元格值

我目前有这个代码如下。 如果单元格是空白的,填充将是绿色的(4)。 当单元格不是空白时,将不会填充。 但如果我希望我的单元格(0,3)填充为黄色,如果单元格值=“是”? 目前有一个“是”或“否”的下拉菜单。

Private Sub worksheet_change(ByVal Target As Range) If Not Intersect(Target, Range("A:A")) Is Nothing Then ActiveSheet.Unprotect If Target = "YES" Then For i = 1 To 9 With Target.Offset(0, i) .Locked = False .FormatConditions.Add Type:=xlExpression, Formula1:="=ISBLANK(" & Target.Offset(0, i).Address & ")" With .FormatConditions(.FormatConditions.Count) .SetFirstPriority .Interior.ColorIndex = 4 End With End With Next i '============================================================================================================== '============================================================================================================== ElseIf Target = "NO" Then For i = 10 To 15 With Target.Offset(0, i) .Locked = False .FormatConditions.Add Type:=xlExpression, Formula1:="=ISBLANK(" & Target.Offset(0, i).Address & ")" With .FormatConditions(.FormatConditions.Count) .SetFirstPriority .Interior.ColorIndex = 4 End With End With Next i Else For i = 1 To 15 With Target.Offset(0, i) .Value = "" .Locked = True .FormatConditions.Delete End With Next i End If ActiveSheet.Protect End If End Sub 

请参阅下面的内容

  For i = 26 To 28 With Target.Offset(0, i) .Locked = False .FormatConditions.Add Type:=xlExpression, Formula1:="=ISBLANK(" & Target.Offset(0, i).Address & ")" With .FormatConditions(.FormatConditions.Count) .SetFirstPriority .Interior.ColorIndex = 45 End With End With If i = 27 AND UCase(Target.Offset(0,i).value) = "YES" Then Target.Offset(0,i).Interior.Color = RGB(255,255,0) Next i 

然后使用Color = 65535如果range.value =“YES”