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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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