running varibiables into vba

P

paul

number,x, from cell A3 and a positive integer, n, from cell B3 then
returns into cell C3 the value of x raised to the power n divided by
n factorial.


where x in cell a3 = 2 and n in cell b3 = 5


im using this formula, but when i run it nothing happens, how do i
make this vba programme run and return the value?

how do i delcare x and n variables intot his workign vba code so that
the vba can run, im not sure how to declre them, how you do it.

thanks



this is the vba programme:


Public Function MyFunction(X As Double, N As Long) As Variant
If (N <= 0&) _
Then
MyFunction = "N must be an integer greater than zero"
Else
MyFunction = (X ^ N) / WorksheetFunction.Fact(N)
End If
End Function


how do i delare these
 
T

Tom Ogilvy

If you are using it in a worksheet

Public Function MyFunction(X As Range, N As Range) As Variant
MyFunction = "Bad Input Values"
If IsNumeric(N.Value) And IsNumeric(X.Value) Then
If N.Value <= 0& Then
MyFunction = "N must be an integer greater than zero"
Else
MyFunction = (X ^ Int(N)) / WorksheetFunction.Fact(Int(N))
End If
End If
End Function
Usage:
=MyFunction(A3,B3)

Worked for me. Function should be placed in a general module (as in
Insert=>Module) rather than a class module such as the worksheet or
thisworkbook modules.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

running a programme 9
programme fucntioning problems errors 2
programme run help 2
vba 2
programme fucntioning problems 1
running into a spreasheet vba programmes 0
run programme error occuring 2
vba coding 3

Top