我的VBA代码遇到了一些问题。我有一些与Bloomberg相关的实时数据,每当单元格的值高于特定阈值时,我想获得一个弹出窗口。要做到这一点,我需要找到一种方法来不断运行我的宏来检查我的条件是否经过验证..但我不知道该怎么做..我目前的VBA代码是:
Private Sub Worksheet_Activate()
Dim i As Long
For i = 2 To 99
If Cells(i, 11).Value > 25000 Then
MsgBox "Last trade on " & Cells(i, 1).Value & " is higher than 25 000"
End If
Next i
End Sub
如果你能帮我解决这个问题,那就太好了!提前致谢
答案 0 :(得分:1)
您可以尝试这样的事情:
Private Sub Worksheet_Activate()
Dim i As Long
Do while (true)
For i = 2 To 99
If Cells(i, 11).Value > 25000 Then
MsgBox "Last trade on " & Cells(i, 1).Value & " is higher than 25 000"
End If
Next i
Application.Wait (Now + TimeValue("0:00:10")) 'wait 10 seconds
Loop
End Sub
编辑:如果相同则停止显示,使用单元格(如10列之外)存储当前值并进行比较。
Private Sub Worksheet_Activate()
Dim i As Long
Do while (true)
For i = 2 To 99
If Cells(i, 11).Value > 25000 Then
If Cells(i, 11).Value <> Cells(i, 1).ValueThen
MsgBox "xxxxx"
Cells(i, 11).Value = Cells(i, 1).Value 'setting value
End If
End If
Next i
Application.Wait (Now + TimeValue("0:00:10")) 'wait 10 seconds
Loop
End Sub