Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default running varibiables into vba

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default running varibiables into vba

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.

--
Regards,
Tom Ogilvy


"paul" wrote:

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


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
RUNNING Avg - how? Boswell Excel Discussion (Misc queries) 2 November 11th 08 04:43 AM
Running an Add-In on the fly Kigol Excel Programming 3 June 13th 07 11:53 PM
Running Ontime's procedure while another function is running? Enter The Excel Programming 1 May 11th 07 05:58 AM
Name of running sub??? Ken Loomis Excel Programming 5 July 13th 05 08:17 PM
running a sub pikus Excel Programming 0 January 29th 04 03:09 PM


All times are GMT +1. The time now is 10:09 PM.

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

About Us

"It's about Microsoft Excel"