PROGRAMME HELP

P

paul

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))),"Wrong
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
 
G

Guest

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
 
A

Arvi Laanemets

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").Range("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").Range("C3").Value=(var1^
var2)/Application.WorksheetFunction.FACT(var2)
End If
 

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
running varibiables into vba 1
vba 2
writing in vba 13
continous assessment help with vba 1
vba coding 3

Top