Excel VBA and Bloomberg BDH formulas and dynamic cells in an Excel sheet?

Helen_RMI

New Member
Joined
Jun 28, 2011
Messages
2
Hi,

I was trying to develop the following Excel VBA code. The main aim is for the code to be able to automatically recognize the dynamic inputs tfor the variables and run the Blooomberg BDH function on the variable values. But it seemed that the "" marks seems to be prohibiting the BDH function to take values from the data variables. After running the code, the formula that has been populated in the excel is "=BDH(tickername, pricetype,dtStart,dtEnd)" instead of =BDH formula that accounts for the variable values. :eeek:

Can any expert enlighten me? thank you a lot! :)

Sub testBDH()

Dim dtStart As Date, dtEnd As Date
Dim tickername, pricetype As String

'then apply the values you've worked out. e.g.

dtStart = CDate("6/30/2010")
dtEnd = CDate("6/01/2011")
tickername = "ST SP Equity"
pricetype = "PX_LAST"

'then use the variables as follows

ActiveCell.FormulaR1C1 = "=BDH(tickername, pricetype,dtStart,dtEnd)"

End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi, welcome to the board :)

It seems like you're on the right track. When placing the formula, your variables shouldn't be w/in the quotes because you want to place the values of the variables; not the text of the variable name itself.

Code:
ActiveCell.Formula = "=BDH(" & tickername & "," & pricetype & "," & dtStart & "," & dtEnd & ")"
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,847
Members
452,948
Latest member
UsmanAli786

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