Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
programme error | Excel Programming | |||
programme error | Excel Programming | |||
tote programme | Excel Programming | |||
Audit Programme | Excel Programming | |||
excel vba programme | Excel Programming |