Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
programme run help
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? 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 or i can use this one, which one do you thinks better? Sub test() '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 how do i delcare x and n variables into working vba code so that the vba can run, im not sure how to decalre them, how you do it. at the minute nothing happens the vba doesnt code it. do i need to put it into a macro. the cell a3 and b3 are on a normal sheet 1 on excel and i need to use vba to calculate into cell C3 the value of x raised to the power n divided by n factorial. I just want to no how to make the code run, im really struggling please please please help!!!!! if any one can help can u explain in great detail so i can get it right thank you |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
programme run help
Since you wrote it as a function, you call it by putting "=myfunction(A3,B3)"
in C3 on the worksheet Peter Richardson "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? 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 or i can use this one, which one do you thinks better? Sub test() '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 how do i delcare x and n variables into working vba code so that the vba can run, im not sure how to decalre them, how you do it. at the minute nothing happens the vba doesnt code it. do i need to put it into a macro. the cell a3 and b3 are on a normal sheet 1 on excel and i need to use vba to calculate into cell C3 the value of x raised to the power n divided by n factorial. I just want to no how to make the code run, im really struggling please please please help!!!!! if any one can help can u explain in great detail so i can get it right thank you |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
programme run help
Paul,
Both of these now work. To get the function to run paste it into a general module and call it with =MyFunction(a1:b1) Modify the cell addresses to suit 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 Sub test() 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 Mike "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? 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 or i can use this one, which one do you thinks better? Sub test() '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 how do i delcare x and n variables into working vba code so that the vba can run, im not sure how to decalre them, how you do it. at the minute nothing happens the vba doesnt code it. do i need to put it into a macro. the cell a3 and b3 are on a normal sheet 1 on excel and i need to use vba to calculate into cell C3 the value of x raised to the power n divided by n factorial. I just want to no how to make the code run, im really struggling please please please help!!!!! if any one can help can u explain in great detail so i can get it right thank you |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to programme this in excel? | Excel Discussion (Misc queries) | |||
PROGRAMME HELP | Excel Programming | |||
error in programme | Excel Discussion (Misc queries) | |||
tote programme | Excel Programming | |||
Audit Programme | Excel Programming |