BDH Formula in Macro VBA

excelnewbie2018

New Member
Joined
Jan 16, 2018
Messages
8
Dear community,

I would like to build a macro from directly obtaining Bloomberg Data (PX_LAST and OP_INT) for a large set of stock.

Has anybody of you already tried to insert the BDH function into a Macro? How did you o it for multiple stocks? Could you create 1 table only?

I am sorry fr this qestion but I am really stuck and I do not even know where I should start.

Thanks in advance for your precious help :)
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I was doing something similar a few years ago, the way I solved it was to write out the BDH functions automatically using this code
Code:
Sub writebdh()
' this is the double quotes character
tt = Chr(34)


Sheets("Stocklist").Select
inarr = Range("Instruments")
cnt = Range("Instruments").Rows.Count


Sheets("Download").Select
For i = 1 To cnt
titl = inarr(i, 1)




s1 = tt & titl & tt
s21 = Cells(6, 6) 'Open
s22 = Cells(6, 7) ' High
s23 = Cells(6, 8) ' low
s24 = Cells(6, 9) ' Last_Price
s2 = tt & s21 & tt & " " & tt & s22 & tt & " " & tt & s23 & tt & " " & tt & s24 & tt
'open price only for this test
s2 = tt & s21 & tt
s3 = tt & Cells(7, 2) & tt  ' Start date


s4 = tt & Cells(7, 4) & tt 'end date
s5 = tt & Cells(5, 5) & tt 'Bartp=T
s6 = tt & "BarSz="
s7 = Cells(2, 9) & tt  ' Period
Endstr = "," & tt & "Dir=V" & tt & "," & tt & "Dts=S" & tt & "," & tt & "Sort=A" & tt & ", " & tt & "Quote=C " & tt & ", " & tt & "UseDPDF=Y " & tt & ")"
frmtxt = "=BDH(" & s1 & "," & s2 & "," & s3 & "," & s4 & "," & s5 & "," & s6 & s7 & Endstr
Sheets("Download").Select
Cells(7, 7 + i * 7).Formula = frmtxt
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,970
Messages
6,175,713
Members
452,667
Latest member
vanessavalentino83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top