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

how can i add error checking to thisvba code to check that it runs
well.

Sub test()
Dim x As Single, n As Integer, i As Integer, fact As Integer
n = Range("b3")
x = Range("a3")
'calculate n factorial
'checking B3
If Range("B3") <= 0 Or Int(Range("B3")) < Range("B3") Then
MsgBox " integer in b3 must be greater then zero"
Exit Sub
End If
fact = 1
For i = 1 To n
fact = fact * i
Next i
'calculate result x ^ n/fact n!
result = x ^ n / fact
Range("c3") = result

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default vba

Paul
What do perceive as "not running well"? In other words, what happens
when it doesn't run well? HTH Otto
"paul" wrote in message
ups.com...
how can i add error checking to thisvba code to check that it runs
well.

Sub test()
Dim x As Single, n As Integer, i As Integer, fact As Integer
n = Range("b3")
x = Range("a3")
'calculate n factorial
'checking B3
If Range("B3") <= 0 Or Int(Range("B3")) < Range("B3") Then
MsgBox " integer in b3 must be greater then zero"
Exit Sub
End If
fact = 1
For i = 1 To n
fact = fact * i
Next i
'calculate result x ^ n/fact n!
result = x ^ n / fact
Range("c3") = result

End Sub



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



All times are GMT +1. The time now is 06:57 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"