我有一个Excel VBA函数,它修改了两个字段flashes the background color for one of them的内容。这是我的代码:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cellTitle As Range
Set cellTitle = Range("J2")
Dim cellTip As Range
Set cellTip = Range("J3")
Title = Application.VLookup(Target.Address, Sheets("Settings").Range("TipsDashboard"), 2, False)
If Not IsError(Title) Then
Tip = Application.VLookup(Target.Address, Sheets("Settings").Range("TipsDashboard"), 3, False)
cellTitle.Value = Title
cellTip.Value = Tip
FadeToWhite (Sheets("Dashboard").Range("$J$3:$K$9"))
End If
End Sub
Sub FadeToWhite(c As Range)
Const SLOWNESS As Long = 50000
Dim i As Long, v
For i = 1 To 255 * SLOWNESS
If i Mod SLOWNESS = 0 Then
v = i / SLOWNESS
c.Interior.Color = RGB(v, 255, v)
DoEvents
End If
Next i
End Sub
出于某种原因,它会填充cellTip
的值,颜色渐渐消失,然后会填充cellTitle
的值。我的延迟最终会慢得多,但SLOWNESS
的较大值确实会使时间变得明显。
我意识到这是一个微不足道的细节,但我真的很想知道它为什么会发生。