在VBA中闪烁的单元格

我有一些代码,当一个单元格有一定的价值时,它的内部改变为红色,其字体为白色。 我想要做的是让文本的颜色每隔一秒钟在白色和红色之间交替,只要细胞内部是红色的(一旦变成红色,它将保持红色)。 我希望用户有一个单元格实际上闪烁的印象。

我写了这个代码:

For r = 6 To 1000 With .Cells(r, 6) While .Interior.Color = RGB(237, 67, 55) .Font.Color = RGB(237, 67, 55) Application.Wait (Now + TimeValue("0:00:01")) .Font.Color = vbWhite Wend End With Next r 

excel只是使第一个红色的内部“闪光”单元格,然后崩溃。 红细胞不连续。

一起去吧:

 Sub Flash_Ahhh() Dim strRange As String Dim rCell As Range Dim iFlasher As Integer lngCounter = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row 'Find last row of data lngCol = ActiveCell.Column ' Find the active column vArr = Split(Cells(1, lngCol).Address(True, False), "$") Col_Letter = vArr(0) 'The Active Column Letter strRange = Col_Letter & "6:" & Col_Letter & lngCounter 'The range of all cells in the active column For Each rCell In Range(strRange).Cells Select Case rCell.Interior.Color Case Is = vbRed For iFlasher = 1 To 10 If rCell.Font.Color = vbRed Then rCell.Font.Color = vbWhite Else rCell.Font.Color = vbRed End If Call WaitFor(0.1) Next iFlasher rCell.Font.Color = vbWhite Case Else End Select Next rCell End Sub 

使用以下来引起时间延迟:

 Sub WaitFor(NumOfSeconds As Single) Dim SngSec As Single SngSec = Timer + NumOfSeconds Do While Timer < SngSec DoEvents Loop End Sub