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


I want to write a program that takes a
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. I will award you bonus marks if you put in some error
checking to ensure that a negative value of n cannot be used. Note
that x can be positive or negative.

this is what i have achieved so far

number 'x' is in cell A4 and number 'n' is in cell A5. to get the
desired output, i key inthe formula

=IF(OR(ISERROR(POWER(A4,B4)),ISERROR(FACT(B4))),"W rong
parameters",POWER(A4,B4)/FACT(B4))


is this all i need to do?? does anyone no any other formulas??

and how to check for error in the programme???

cheers

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default PROGRAMME HELP

I would use a custom function that you pass two parameter. You can then put
it any place in you workbook. It will work just like the standard excel
functions.

enter formula into C3
=PowerFact(A3,B3)

Function PowerFact(X As Range, N As Range)

If (X = 0) And (N = 0) Then
PowerFact = (X ^ N) / WorksheetFunction.Fact(N)
Else
PowerFact = "Wrong parameters"
End If
End Function

"paul" wrote:


I want to write a program that takes a
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. I will award you bonus marks if you put in some error
checking to ensure that a negative value of n cannot be used. Note
that x can be positive or negative.

this is what i have achieved so far

number 'x' is in cell A4 and number 'n' is in cell A5. to get the
desired output, i key inthe formula

=IF(OR(ISERROR(POWER(A4,B4)),ISERROR(FACT(B4))),"W rong
parameters",POWER(A4,B4)/FACT(B4))


is this all i need to do?? does anyone no any other formulas??

and how to check for error in the programme???

cheers


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 510
Default PROGRAMME HELP

Hi


Is there some reason that common worksheet functions will not do?

=IF(B3<0,"Error",POWER(A3,B3)/FACT(B3))

When it must be a VBA Code, then you can use worksheet functions from there
too.

....
If Workbooks("YourWorkbook").Sheets("YourSheet").Rang e("B3")<0 Then
' actions when n is negative
...
Else
var1=Workbooks("YourWorkbook").Sheets("YourSheet") .Range("A3")
var2=Workbooks("YourWorkbook").Sheets("YourSheet") .Range("B3")
Workbooks("YourWorkbook").Sheets("YourSheet").Rang e("C3").Value=(var1^
var2)/Application.WorksheetFunction.FACT(var2)
End If

--
Arvi Laanemets
( My real mail address: arvi.laanemets<attarkon.ee )



"paul" wrote in message
ups.com...

I want to write a program that takes a
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. I will award you bonus marks if you put in some error
checking to ensure that a negative value of n cannot be used. Note
that x can be positive or negative.

this is what i have achieved so far

number 'x' is in cell A4 and number 'n' is in cell A5. to get the
desired output, i key inthe formula

=IF(OR(ISERROR(POWER(A4,B4)),ISERROR(FACT(B4))),"W rong
parameters",POWER(A4,B4)/FACT(B4))


is this all i need to do?? does anyone no any other formulas??

and how to check for error in the programme???

cheers



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 error paul[_17_] Excel Programming 1 July 26th 07 05:46 PM
programme error paul[_17_] Excel Programming 1 July 26th 07 05:05 PM
tote programme Mike Excel Programming 4 February 3rd 06 12:30 PM
Audit Programme Steved[_3_] Excel Programming 6 September 7th 04 01:58 AM
excel vba programme sarasa[_6_] Excel Programming 3 June 14th 04 07:27 AM


All times are GMT +1. The time now is 06:52 AM.

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"