ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   vba (https://www.excelbanter.com/excel-programming/396465-vba.html)

paul[_17_]

vba
 
im writing a VBA programme where x = 2 in cell A3 and cell B3 = 5

and in cell C3


=IF(B3<=0,"B3 must be integer greater than zero",(A3^B3)/FACT(B3))


can anyone help me write a VBA programmeto ensure that x from cell
a3
and n from cell b3 return in cell c3 the value of x raised tot he n
divided by n factorial


where x is 2 and n is 5


many thanks as im struggling on how to do this


p45cal[_50_]

vba
 
maybe:

Sub blah()
'checking B3:
If Range("B3") < 1 Or Int(Range("B3")) < Range("B3") Then
MsgBox "B3 should be an integer greater than 0"
Exit Sub
End If
Range("C3") = Range("A3") ^ Range("B3") /
Application.WorksheetFunction.Fact(Range("B3"))
End Sub


--
p45cal


"paul" wrote:

im writing a VBA programme where x = 2 in cell A3 and cell B3 = 5

and in cell C3


=IF(B3<=0,"B3 must be integer greater than zero",(A3^B3)/FACT(B3))


can anyone help me write a VBA programmeto ensure that x from cell
a3
and n from cell b3 return in cell c3 the value of x raised tot he n
divided by n factorial


where x is 2 and n is 5


many thanks as im struggling on how to do this



Bill Renaud

vba
 
A VBA function might be as follows (the "&" after the 0 declares the 0
to be a long data type):

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

In cell C3, put the worksheet formula:

=MyFunction(A3,B3)

--
Regards,
Bill Renaud





All times are GMT +1. The time now is 11:46 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com