excel bloomberg function @BDH not updating fully when using vba to update date range

43 Views Asked by At

my excel vba to update bloomberg formula BDH is not working. I use a bloomberg formula to bring in a tbill historically. It has a start date and end date and I need to update the end date daily. If I manually type it in it refreshes all the data just fine. If I do it in vba the historical section does not update.

here is the excel formula

=@BDH(B1,B6:C6,B2,B3,"Dir=V","Dts=S","Sort=D","Quote=C","QtTyp=P","Days=T",CONCATENATE("Per=c",B4),"DtFmt=D","UseDPDF=Y","cols=3;rows=262")

this is what I have tried

Range("B3").Select
ActiveCell.FormulaR1C1 = "2/15/2024"
Range("B3").Select
ActiveCell.FormulaR1C1 = "3/1/2024"
Range("B4").Select


'
'
    wksheet2.Cells(3, 2).Select

    wksheet2.Cells(7, 1).Select
        ActiveCell.Replace What:="=", Replacement:="=", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
    Cells.Find(What:="=", After:=ActiveCell, LookIn:=xlFormulas2, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate


Application.Run "RefreshData"
Application.Run "RefreshCurrentSelection"
Application.Run "RefreshEntireWorksheet"
Application.Run "RefreshEntireWorkbook"
Application.Run "RefreshAllWorkbooks"
Application.Run "RefreshAllStaticData"

    Application.Calculate
    ActiveSheet.Calculate


    Sleep 15000

screenshot of excel

basically, cell a7 updates just fine... but the dates in a8-a100 do not update. but again, if I type it in manually everything updates just fine.

does anyone know what I am doing wrong

I tried putting it in a different method and it still doesn't work.

    Range("B3").Select
    ActiveCell.FormulaR1C1 = "2/15/2024"
    Range("B3").Select
    ActiveCell.FormulaR1C1 = "3/1/2024"
    Range("B4").Select
    
    'Range("A7").Select
    'ActiveCell.Formula2="@BDH(B1,B6:C6,B2,B3,"Dir=V","Dts=S","Sort=D","Quote=C","QtTyp=P","Days=T",CONCATENATE("Per=c",B4),"DtFmt=D","UseDPDF=Y","cols=3;rows=262")"
        Range("A7").Select
    Selection.Copy
    ActiveSheet.Paste
    
'
'
'    wksheet2.Cells(3, 2).Select
'
    wksheet2.Cells(7, 1).Select
        ActiveCell.Replace What:="=", Replacement:="=", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
    Cells.Find(What:="=", After:=ActiveCell, LookIn:=xlFormulas2, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate


Application.Run "RefreshData"
Application.Run "RefreshCurrentSelection"
Application.Run "RefreshEntireWorksheet"
Application.Run "RefreshEntireWorkbook"
Application.Run "RefreshAllWorkbooks"
Application.Run "RefreshAllStaticData"

    Application.Calculate
    ActiveSheet.Calculate
    
    Application.OnTime (Now + TimeValue("00:00:15")), "InitiateProcess"
0

There are 0 best solutions below