首页 > 解决方案 > VBA 布隆伯格公式

问题描述

我的代码有问题,这里是:

Sheets("Data - Backtest").Cells(5, linCompteur - 1).FormulaR1C1 = _
  "=BDH(R[-3]C[1],""PX_LAST"",""ED-"" & " & .Cells(6, 5).Value & " & ""AYA""," & .Cells(7, 5).Value & ", **""per="" & " & .Cells(9, 6).Value & "** , **""fx="" & " & .Cells(8, 5).Value & "** ,""Days=W"",""Fill=P"",""cols=2"")"

在 Excel 中它给出了这个,

=BDH(R[-3]C[1];"PX_LAST";"ED-" & 5 & "AYA";; **"per=" & d**; **"fx=" & EUR**;"Days=W";"Fill=P";"cols=2")

我知道问题出在哪里,是 d 和 EUR,应该是这样的:

=BDH(R[-3]C[1];"PX_LAST";"ED-" & 5 & "AYA";;**"per=" & "d"**;**"fx=" & "EUR"**;"Days=W";"Fill=P";"cols=2";"cols=2;rows=1305")

但我不知道如何为 VBA 中的等效项执行此操作。

标签: excelvbaformulabloomberg

解决方案


我将一些字符串连接放在一起,似乎没有任何理由将它们分开。

workSheets("Data - Backtest").Cells(5, linCompteur - 1).FormulaR1C1 = _
  "=BDH(R[-3]C[1], ""PX_LAST"", ""ED-" & .Cells(6, 5).Value & "AYA"", " & .Cells(7, 5).Value & ", ""per=" & .Cells(9, 6).Value & """ , ""fx=" & .Cells(8, 5).Value & """ , ""Days=W"", ""Fill=P"", ""cols=2"")"

这是工作表上的结果。

=BDH(R[-3]C[1], "PX_LAST", "ED-5AYA", , "per=d" , "fx=EUR" , "Days=W", "Fill=P", "cols=2")

推荐阅读