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 a programme


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?

the vba programmes ok its just no running anything or doing anything
to my spreadsheet

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default running a programme

Hi Paul:

in A3, I put 2.1
in B3, I put 3
in C3, I entered:
=myfunction(A3,B3) which displays:
1.5435


In another cell:
=2.1*2.1*2.1/6
which displays the same thing.


Make sure your function is in a standard module. It seems to calculate
correctly.


--
Gary''s Student - gsnu200741


"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?

the vba programmes ok its just no running anything or doing anything
to my spreadsheet

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default running a programme

Do you have x and n declared public as equaling A3 and B3? There is nothing
in the function code to tell it where to find the value of X or N. If x and
n are empty when the code is run, then you will get no result.

"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?

the vba programmes ok its just no running anything or doing anything
to my spreadsheet

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default running a programme

On 2 Sep, 15:32, JLGWhiz wrote:

oh how would i declare that then?









Do you have x and n declared public as equaling A3 and B3? There is
nothing
in the function code to tell it where to find the value of X or N. If x and
n are empty when the code is run, then you will get no result.



"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?


the vba programmes ok its just no running anything or doing anything
to my spreadsheet


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- Hide quoted text -


- Show quoted text -



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default running a programme

Are you trying to run your function from the spreadsheet? If so, you need to
put your function in a Module, not in a sheet or workbook code window. Click
Insert/Module from the VBA menu bar; then cut your function from the code
window it is now in and paste it into the Module's code window. You should
now be able to put

=MyFunction(A3,B3)

in a cell on the spreadsheet and it should work fine (well, fine within the
limitations of the FACT function's level of accuracy... after FACT(14), the
FACT function returns approximated floating point values).

Rick


"paul" wrote in message
oups.com...
On 2 Sep, 15:32, JLGWhiz wrote:

oh how would i declare that then?

Do you have x and n declared public as equaling A3 and B3? There is
nothing
in the function code to tell it where to find the value of X or N. If x
and
n are empty when the code is run, then you will get no result.

"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?


the vba programmes ok its just no running anything or doing anything
to my spreadsheet


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- Hide quoted text -


- Show quoted text -






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default running a programme








thanks fot that, really useful

which bit is the function i should cut then?












On 2 Sep, 16:10, "Rick Rothstein \(MVP - VB\)"
wrote:
Are you trying to run your function from the spreadsheet? If so, you need to
put your function in a Module, not in a sheet or workbook code window. Click
Insert/Module from the VBA menu bar; then cut your function from the code
window it is now in and paste it into the Module's code window. You should
now be able to put

=MyFunction(A3,B3)

in a cell on the spreadsheet and it should work fine (well, fine within the
limitations of the FACT function's level of accuracy... after FACT(14), the
FACT function returns approximated floating point values).

Rick

"paul" wrote in message

oups.com...



On 2 Sep, 15:32, JLGWhiz wrote:


oh how would i declare that then?


Do you have x and n declared public as equaling A3 and B3? There is
nothing
in the function code to tell it where to find the value of X or N. If x
and
n are empty when the code is run, then you will get no result.


"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?


the vba programmes ok its just no running anything or doing anything
to my spreadsheet


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- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default running a programme

I am not sure what you are asking here... can you clarify your question a
little more?

Rick

which bit is the function i should cut then?

\
On 2 Sep, 16:10, "Rick Rothstein \(MVP - VB\)"
wrote:
Are you trying to run your function from the spreadsheet? If so, you need
to
put your function in a Module, not in a sheet or workbook code window.
Click
Insert/Module from the VBA menu bar; then cut your function from the code
window it is now in and paste it into the Module's code window. You
should
now be able to put

=MyFunction(A3,B3)

in a cell on the spreadsheet and it should work fine (well, fine within
the
limitations of the FACT function's level of accuracy... after FACT(14),
the
FACT function returns approximated floating point values).

Rick

"paul" wrote in message

oups.com...



On 2 Sep, 15:32, JLGWhiz wrote:


oh how would i declare that then?


Do you have x and n declared public as equaling A3 and B3? There is
nothing
in the function code to tell it where to find the value of X or N. If
x
and
n are empty when the code is run, then you will get no result.


"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?


the vba programmes ok its just no running anything or doing anything
to my spreadsheet


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- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default running a programme

Your function worked fine for me.

Are you sure you enabled macros when the workbook was opened? But that would
have returned a #Name? error.

Are you sure you don't have calculation set to manual?

What do you mean when you say "nothing happens"?

And you could use a function like:

=(A3^B3)/FACT(B3)
or with that check:
=IF(B3<0,"N must be an integer greater than zero",(A3^INT(B3)/FACT(INT(B3))))

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?

the vba programmes ok its just no running anything or doing anything
to my spreadsheet

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


--

Dave Peterson
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
PROGRAMME HELP paul[_17_] Excel Programming 2 July 30th 07 11:46 AM
error in programme biker man Excel Discussion (Misc queries) 4 July 26th 07 09:01 PM
programme error paul[_17_] Excel Programming 1 July 26th 07 05:46 PM
Linking with other programme Rao Ratan Singh New Users to Excel 1 January 31st 06 07:16 PM
Can't access programme hol015 Excel Discussion (Misc queries) 1 August 1st 05 01:14 AM


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