Home » excel » excel – VBA Bloomberg Formula

excel – VBA Bloomberg Formula

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a problem with my code, here it is:

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"")"

In the Excel it gives this,

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

I see where is the problem, it’s d and EUR, it should be this:

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

but I don’t know how to do this for the equivalent in VBA.

How to&Answers:

I brought some of the string concatenations together where there didn’t seem any reason to separate them.

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"")"

This is the result on the worksheet.

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