我想先创建一个从Bloomberg提取数据的过程,然后用它们的值替换所有公式。到目前为止,我提出了两种方法。 1.使用BDH代码首先为一系列单元格提取数据,然后在填充所有数据后将所有内容粘贴为值。 2.在代码执行下一个单元格之前,使用BDH代码提取数据并立即将其粘贴为值。以下是我的代码(我使用了第二种方法):
For j = lastrow - 6 To lastrow
time = ActiveSheet.Cells(j, 1)
For i = 3 To lastcol 'starts from Col C
ticker = ActiveSheet.Cells(2, i).Value
ActiveSheet.Cells(j, i).Formula = "= BDH(""" & ticker & """,""Last_Price"",""" & time & """,""" & time & """, ""days=a"", ""fill=p"")"
Application.Wait (Now + TimeValue("00:00:03"))
ActiveSheet.Cells(j, i).Value = ActiveSheet.Cells(j, i).Value
Next
Next
当我在Bloomberg上运行此代码时,它不会粘贴为值,它们仍然是代码。我觉得Application.Wait中的3秒还不够长,但我想改变我的整个方法,并且不想计算填充一个值的秒数。有没有人有这方面的经验,可以提供更快的方法来填充彭博的价值观?虽然我上面提到的第一种方法也是一种替代方法,但我更喜欢在填充数据时获取值。谢谢!
答案 0 :(得分:0)
我实际上想出了我自己的问题的答案..但它仍然使用OnTime ..不确定是否有其他方法可以做到这一点
Sub pulldata()
For j = lastrow - 6 To lastrow
time = ActiveSheet.Cells(j, 1)
For i = 3 To lastcol 'starts from Col C
ticker = ActiveSheet.Cells(2, i).Value
ActiveSheet.Cells(j, i).Formula = "= BDH(""" & ticker & """,""Last_Price"",""" & time & """,""" & time & """, ""days=a"", ""fill=p"")"
Application.OnTime Now + TimeValue("00:00:03"), "pastespecial"
Next
Next
end sub
'start a new sub to terminate previous macro
sub pastespecial()
Dim lastrow As Integer
lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Dim lastcol As Integer
lastcol = ActiveSheet.Cells(1, ActiveSheet.Columns.Count).End(xlToLeft).Column
Set myrange = Range(ActiveSheet.Cells(lastrow - 6, 3), ActiveSheet.Cells(lastrow, lastcol))
myrange.Value = myrange.Value
end sub