我编写了一个代码,每当值在单元格中发生变化时,另一个单元格会突出显示,但是在下面的代码中它正常工作。
不幸的是,如果数量低于或高达500,它正确地突出显示单元格B29:C29当下一个数量在单元格C15中下降1500然后B31:C31被突出显示但是B29:C29也是我需要的任何其他宏应用之前需要清除
Sub Highlight_Cells()
If Range("C18") >= "500" Then
Range("B29:C29").Interior.Color = vbYellow
End If
If Range("C18") >= "501" And Range("C18") <= "1000" Then
Range("B30:C30").Interior.Color = vbYellow
End If
If Range("C18") >= "1001" And Range("C18") <= "2000" Then
Range("B31:C31").Interior.Color = vbYellow
End If
If Range("C18") >= "2001" And Range("C18") <= "5000" Then
Range("B32:C32").Interior.Color = vbYellow
End If
If Range("C18") > "5000" Then
Range("B33:C33").Interior.Color = vbYellow
End If
End Sub
答案 0 :(得分:0)
您需要将您的颜色视为开关。如果他们打开了,那么除非你告诉他们,否则他们不会关闭。
试试这个
Sub Highlight_Cells()
If Range("C18") >= "500" Then
Range("B29:C29").Interior.Color = vbYellow
Else
Range("B29:C29").Interior.ColorIndex = 0
End If
If Range("C18") >= "501" And Range("C18") <= "1000" Then
Range("B30:C30").Interior.Color = vbYellow
Else
Range("B30:C30").Interior.ColorIndex = 0
End If
If Range("C18") >= "1001" And Range("C18") <= "2000" Then
Range("B31:C31").Interior.Color = vbYellow
Else
Range("B31:C31").Interior.ColorIndex = 0
End If
If Range("C18") >= "2001" And Range("C18") <= "5000" Then
Range("B32:C32").Interior.Color = vbYellow
Else
Range("B32:C32").Interior.ColorIndex = 0
End If
If Range("C18") > "5000" Then
Range("B33:C33").Interior.Color = vbYellow
Else
Range("B33:C33").Interior.ColorIndex = 0
End If
End Sub