我正在尝试让U列中不等于2.04或3.59的所有单元格都改变单元格颜色。
代码如下:
Private Sub Cell_Color_Change()
For Each cell In Range("U2:U19004")
If cell.Value <> 2.04 Or 3.59 Then cell.Interior.ColorIndex = 3
Next cell
End Sub
由于某些原因,代码将整个列变为红色。我试过使用条件格式,同样的事情也发生了。请帮帮忙。谢谢!
发布于 2018-12-18 03:38:05
使用VBA设置条件格式。
Option Explicit
Private Sub set_Cell_Color_Change()
With Range("U2:U19004")
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=and(round($u2, 2)<>2.04, round($u2, 2)<>3.59)"
.FormatConditions(.FormatConditions.Count).Font.Color = vbRed
End With
End Sub
https://stackoverflow.com/questions/53821752
复制相似问题