Code to write formula with a cell reference

qwertty

New Member
Joined
Jun 22, 2011
Messages
2
I have a worksheet with hundreds of Bloomberg formulas in it that I need to change regularly. I only need to change the date information, everything else stays the same (see the formula below). What I'd like to do is enter a new date in a cell and run a macro to change all the previous dates to this new date. A simple Find & Replace macro won't work because I need to update the formulas with dates from the prior two weeks (they overlap eachother using find/replace).

Here's one of the formulas I need to change:


=BDH("CL1 Comdty","PX_LAST","6/24/2011","6/24/2011","Dir=V","Dts=H","Sort=A","Quote=C","QtTyp=P","Days=A","Per=cd","DtFmt=D","Fill=P","UseDPDF=Y")

Basically, I want the macro to write the formula as you see it, but with a reference to a cell with the new date (e.g., change "6/24/2011" to some new date). Bloomberg requires the formula to appear EXACTLY as above.

I want to do something similiar to what I found in this thread but I'm having trouble getting it to work: http://www.mrexcel.com/forum/showthread.php?t=64290

I'm a relative newb with VBA. PLEASE HELP!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I don't have access to the function so I can't do any testing.

I am assuming you have tried using cell referernce instead of the date typed out and it didn't work.

Code:
=BDH("CL1 Comdty","PX_LAST",A1,A2,"Dir=V","Dts=H","Sort=A","Quote=C","QtTyp=P","Days=A","Per=cd","DtFmt=D","Fill=P","UseDPDF=Y")

Where A1 is the start date and A2 is the end date.

Try wrapping the cell reference in the TEXT function, that is if you haven't already. I think it should work as the TEXT function returns a string and not the serial date. I suspect the BDH function requires that dates be passed as strings so this might just solve the problem without a macro.


Code:
TEXT($A$1,"mm/dd/yyyy")
TEXT($A$2,"mm/dd/yyyy")

=BDH("CL1 Comdty","PX_LAST",TEXT($A$1,"mm/dd/yyyy"),TEXT($A$2,"mm/dd/yyyy"),"Dir=V","Dts=H","Sort=A","Quote=C","QtTyp=P","Days=A","Per=cd","DtFmt=D","Fill=P","UseDPDF=Y")

Let me know if the above works.
 
Upvote 0

Forum statistics

Threads
1,216,350
Messages
6,130,139
Members
449,560
Latest member
mattstan2012

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