闪烁select内的单元格

我正在使用使某些单元格闪烁的代码。 我修改了代码,只让选中的单元格闪烁。 问题在于,在改变select之后,macros不会“留在”单元格中。 例如:如果我select单元格B6并运行macros – 它开始闪烁,然后我select单元格B7和B6停止闪烁但B7启动,甚至没有运行macros。 我怎么能解决这个问题?

当前代码:

Option Explicit Dim NextBlink As Double Sub StartBlinking() If Selection.Interior.ColorIndex = 3 Then Selection.Interior.ColorIndex = 0 Else Selection.Interior.ColorIndex = 3 End If NextBlink = Now + TimeSerial(0, 0, 0.6) Application.OnTime NextBlink, "StartBlinking", , True End Sub 

尝试这个:

 Option Explicit Dim NextBlink As Double Dim blinkingcells As Range Sub StartBlink() 'call this make current cell start blinking If blinkingcells Is Nothing Then 'start blinking Set blinkingcells = Selection Call Blinking Else 'blinking already, just add more blinkingcells Set blinkingcells = Union(blinkingcells, Selection) End If End Sub Sub Blinking() 'make cells in global range "blinkingcell" blink Dim cell As Range For Each cell In blinkingcells If cell.Interior.ColorIndex = 3 Then cell.Interior.ColorIndex = 0 Else cell.Interior.ColorIndex = 3 End If Next NextBlink = Now + TimeSerial(0, 0, 0.6) Application.OnTime NextBlink, "Blinking", , True End Sub