Creating a Formula in VBA that uses Bloomberg (BDP) Function

  • I end up writing this formula:


    =if(bdp(A2&" Equity","GICS_SECTOR_NAME")="#N/A N/A",bdp(A2&" Equity","FUND_INDUSTRY_FOCUS"),bdp(A2&" Equity","GICS_SECTOR_NAME"))


    about 3x a day, which gets pretty cumbersome. I wanted to write a Public Function to do it, but am not quite sure how.


    I tried this way:


    Code
    1. Public Function BDPSector(Ticker As String) As String
    2. BDPSector = IF(BDP(Ticker & " Equity","GICS_SECTOR_NAME")="N/A N/A",BDP(Ticker & " Equity","FUND_INDUSTRY_FOCUS"),_
    3. BDP(Ticker & " Equity","GICS_SECTOR_NAME"))
    4. End Function


    and this way:


    Code
    1. Public Function BDPSector(Ticker As String) As String
    2. If BDP(Ticker & "" Equity"","GICS_SECTOR_NAME") = "#N/A N/A" Then
    3. BDPSector = "=BDP(Ticker & "" Equity"",""FUND_INDUSTRY_FOCUS"")"
    4. Else
    5. BDPSector = "=BDP(Ticker & "" Equity"",""GICS_SECTOR_NAME"")"
    6. End If
    7. End Function


    Neither of which worked. I am stumped. I'm not sure if this is possible or if I'm doing something wrong... Please anyone help?

  • Re: Creating a Formula in VBA that uses Bloomberg (BDP) Function


    kristin31,


    The Forum Rules are clear on the use of code tags when posting VBA code - - please take the time to read them.


    Edit your post to add the missing code tags, which are used like so;


    [COLOR="navy"]How to use code tags[/COLOR]


    [noparse]

    Code
    1. [/noparse]
    2. [COLOR="navy"]your code goes between these tags[/COLOR]
    3. [noparse]

    [/noparse]


    Thanks,