Results 1 to 2 of 2

msgbox vbyesno

Threaded View

  1. #1
    Registered User
    Join Date
    06-13-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    4

    msgbox vbyesno

    Hi

    I am struggling to work out how to get the vbyesno statements from a msgbox to work for my user defined function below.
    the statements are

    MsgBox "You have selected to use " & N & " days" & " of data" _
    & " and you have selected a price range of:" & PriceRange.Address(external:=True) & "," & " is this OK?", vbYesNo
    If MsgResult = vbNo Then End

    and

    msgBox "Would you like to use the annualised volatility to calculate the sharpe ratio of the selected range?", vbYesNo
    If MsgResult = vbNo Then Exit Function


    However both the do not work as the function keeps running. Please how can i get them to work and end the procedure once no is clicked? coding below.

    Thanks

    Function StkVol(N, PriceRange)
    
    '-----------------Declaring Variables---------------------------------'
    
    Dim i, DlyRet()                                     'Daily return at time i
    ReDim DlyRet(N - 1)                              'Dynamic range dependent on user input N
    Dim MsgResult As VbMsgBoxResult
    
    '*****************Check Input Data *************************************'
    
    MsgBox "You have selected to use " & N & " days" & " of data" _
    & " and you have selected a price range of:" & PriceRange.Address(external:=True) & "," & " is this OK?", vbYesNo
    If MsgResult = vbNo Then End
       
    MsgBox "Please note that prices must be arranged from newest to oldest"
    
    '*****************Calculation********************************************'
    'Calculate daily returns
    For i = 1 To N - 1   'Specifying price range dependent on user input N
    
        DlyRet(i) = Log(PriceRange(i) / PriceRange(i + 1)) 'In VBA Log function returns the natural logarithm of a number
    Next
    
    'Calculate and annualize standard deviation
    StkVol = Application.StDev(DlyRet) * Sqr(252)   '252 average number of trading days in a year
    
    MsgBox "The annualised volatility for your selected range is: " & StkVol & ""
    
    MsgBox "Would you like to use the annualised volatility to calculate the sharpe ratio of the selected range?", vbYesNo
        If MsgResult = vbNo Then Exit Function
    Last edited by newbielondon; 06-18-2012 at 06:34 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1