#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default debug -

I am new to VBA..i wrote the following code..it basically take 5
variables and use as imputs for a a formula.
i won't work for me..can someone help see what is wrong. Thanks for
your help!

Option Explicit

Private Sub CommandButton1_Click()

Dim Spot As Double
Dim strike As Double
Dim RF As Double
Dim Vol As Double
Dim YTM As Double

Dim Call_PX As Variant
Dim d1 As Variant
Dim d2 As Variant
Dim CallPx As Variant

On Error GoTo EndMacro

Spot = ActiveCell.Range("B12").Value
strike = ActiveCell.Range("B13").Value
RF = ActiveCell.Range("B14").Value
YTM = ActiveCell.Range("B15").Value
Vol = ActiveCell.Range("B16").Value

d1 = (Log(Spot / strike) + (RF + (0.5 * Vol ^ 2)) * YTM) / (Vol * YTM
^ 0.5)
d2 = d1 - Vol * YTM ^ 0.5
CallPx = Spot * WorksheetFunction.NormSDist(d1) - strike * Exp(-RF *
YTM) * WorksheetFunction.NormSDist(d2)
Range("B18").Value = CallPx
EndMacro:
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default debug -

It is valid but any error will throw and error and exit the procedure
without a by your leave.

Your fomulae is complex and consequently your input values must comply with
some rules about their valid ranges, dependencies with other values etc...
I recommend that you build these into the code so that each input error can
be detected before you get the blank response.

At the very least try check the intermediate formulae for values d1, and d2,
you are going to get overflows and not know it, the way it stands at
present.

Cheers
Nigel

wrote in message
m...
I am new to VBA..i wrote the following code..it basically take 5
variables and use as imputs for a a formula.
i won't work for me..can someone help see what is wrong. Thanks for
your help!

Option Explicit

Private Sub CommandButton1_Click()

Dim Spot As Double
Dim strike As Double
Dim RF As Double
Dim Vol As Double
Dim YTM As Double

Dim Call_PX As Variant
Dim d1 As Variant
Dim d2 As Variant
Dim CallPx As Variant

On Error GoTo EndMacro

Spot = ActiveCell.Range("B12").Value
strike = ActiveCell.Range("B13").Value
RF = ActiveCell.Range("B14").Value
YTM = ActiveCell.Range("B15").Value
Vol = ActiveCell.Range("B16").Value

d1 = (Log(Spot / strike) + (RF + (0.5 * Vol ^ 2)) * YTM) / (Vol * YTM
^ 0.5)
d2 = d1 - Vol * YTM ^ 0.5
CallPx = Spot * WorksheetFunction.NormSDist(d1) - strike * Exp(-RF *
YTM) * WorksheetFunction.NormSDist(d2)
Range("B18").Value = CallPx
EndMacro:
End Sub





----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! 100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Debug on userform Jase Excel Discussion (Misc queries) 1 May 28th 08 05:00 PM
DeBug Ollie Excel Discussion (Misc queries) 4 April 28th 06 03:17 PM
help with debug Rusty New Users to Excel 3 February 2nd 05 03:16 AM
Row deletion debug Tom Ogilvy Excel Programming 0 November 14th 03 03:01 PM
debug help Tom Ogilvy Excel Programming 0 August 27th 03 07:10 PM


All times are GMT +1. The time now is 03:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"