尽pipe有条件格式,但在excell中闪烁的单元格

我有一些代码,使单元格在预定义的范围内,从白色到红色的闪光颜色。

对于我的目的,我需要这个代码只在具有特定值的单元格上工作 – 例如任何数值小于50的单元格。

在整个范围内工作的代码如下所示

Public NextFlash As Double Public Const FR As String = "Sheet1!B3:D6" Sub StartFlashing() If Range(FR).Interior.ColorIndex = 3 Then Range(FR).Interior.ColorIndex = xlColorIndexNone Else Range(FR).Interior.ColorIndex = 3 End If NextFlash = Now + TimeSerial(0, 0, 1) Application.OnTime NextFlash, "StartFlashing", , True End Sub Sub StopFlashing() Range(FR).Interior.ColorIndex = xlColorIndexNone Application.OnTime NextFlash, "StartFlashing", , False End Sub 

像这样看待每个细胞。

避免查看每个单元格的另一种方法是更改"Sheet1!B3:D6"以便只将其设置为小于50的单元格。但这需要不断跟踪并重新评估事件更改的范围。

所以对于12个单元的范围,下面的循环方法就足够了。

 Public NextFlash As Double Public Const FR As String = "Sheet1!B3:D6" Sub StartFlashing() Dim rng1 As Range For Each rng1 In Range(FR).Cells If rng1.Value < 50 Then If rng1.Interior.ColorIndex = 3 Then rng1.Interior.ColorIndex = xlColorIndexNone Else rng1.Interior.ColorIndex = 3 End If Else rng1.Interior.ColorIndex = xlColorIndexNone End If Next NextFlash = Now + TimeSerial(0, 0, 1) Application.OnTime NextFlash, "StartFlashing", , True End Sub Sub StopFlashing() Range(FR).Interior.ColorIndex = xlColorIndexNone Application.OnTime NextFlash, "StartFlashing", , False End Sub