我有一个包含300,000 BDH公式的Excel工作表,用于下载证券价格。
我想
但是,我不知道Excel何时完成填充彭博数据,因此很难确定执行2)和3)的时间。
我已经写了VBA,但不确定是否可以使用
在hostvars
Module1
在“此工作簿”中
Sub CheckFormulas()
If Application.CalculationState = xlDone Then
With Worksheets("Sheet1").UsedRange
.Value = .Value
End With
Else
Application.OnTime Now + TimeValue("00:30:00"), "CheckFormulas"
ActiveWorkbook.Close Savechanges:=True
End If
End Sub
因此,理论上它应该起作用的方式是:
我想知道这是否是实现我的目标的最佳方法,并且想知道Private Sub Run()
Call CheckFormulas
End Sub
是否兼容或与Bloomberg公式BDH兼容?
答案 0 :(得分:1)
在生产环境中,我们使用一个单元格来检查是否存在公式中带有“ Req”的单元格:
=SUM(IFERROR(FIND("Req", _range_to_check_with_formulas_ ),0))
在VBA Sub中,我们使用WHILE LOOP测试单元格值:
while cell_to_test.value <> 0
Application.Calculate
Application.RTD.RefreshData
DoEvents
Wend
Call _sub_to_do_some_stuff_
答案 1 :(得分:0)
基于@stexcec 的回答,因为我不想在工作表中添加测试单元格,所以我使用 VBA 根据值搜索 "requesting"
。以下函数用于在包含彭博公式的 "requesting"
中查找 Range
:
Function IsFinished(ws As Worksheet) As Boolean
Dim i, j, LastRow, LastCol As Integer
Dim r, c As Range
LastRow = ws.Range("A1").End(xlDown).Row
LastCol = ws.Range("A1").End(xlToRight).Column
Set r = ws.Range(ws.Cells(1, 1), ws.Cells(LastRow, LastCol))
Set c = r.Find("Requesting", LookIn:=xlValues)
If c Is Nothing Then
IsFinished = True
Else
IsFinished = False
End If
End Function
然后,类似于@stexcec的回答,以下代码用于等待所有单元格刷新:
' Wait until updated
Do While True
Application.Calculate
Application.RTD.RefreshData
DoEvents
If IsFinished(Application.ActiveSheet) Then
Exit Do
End If
Loop