Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default how to code factorial in Excel

I am trying to code the factorial function in VBA in Excel.
I know I can use the FACT() in the worksheet, but somehow I can't use
the same function when I am writing the VBA. It gave error and said
"sub or function not defined". I did macro recording and copy the
code to my sub-function and try to run it, it gave error again. Can
someone help? Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default how to code factorial in Excel

This syntax works for me:

Application.WorksheetFunction.Fact(5)

--
Best Regards
Leo Heuser

Followup to newsgroup only please.

skrev i en meddelelse
m...
I am trying to code the factorial function in VBA in Excel.
I know I can use the FACT() in the worksheet, but somehow I can't use
the same function when I am writing the VBA. It gave error and said
"sub or function not defined". I did macro recording and copy the
code to my sub-function and try to run it, it gave error again. Can
someone help? Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default how to code factorial in Excel

" wrote:

I am trying to code the factorial function in VBA in Excel.
I know I can use the FACT() in the worksheet, but somehow I can't use
the same function when I am writing the VBA. It gave error and said
"sub or function not defined". I did macro recording and copy the
code to my sub-function and try to run it, it gave error again. Can
someone help? Thanks.


If Leo's answer doesn't solve your problem, try this. Make sure you put in in a code module (as opposed to a sheet module).

Function Factorial(Num as integer)
Dim i as integer, answer as double
answer = 1
For i = 1 to Num
answer = answer * i
Next i
Factorial = answer
End Function
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
is it posible to have a formula for factorial via vba code? thread Excel Worksheet Functions 4 August 29th 14 11:02 AM
Factorial question M.M Excel Worksheet Functions 6 June 8th 09 04:33 PM
Factorial Listing Branson Excel Discussion (Misc queries) 3 June 6th 08 04:18 PM
Factorial (like =FACT) function? mr tom Excel Worksheet Functions 8 June 13th 06 01:45 AM
Help? Inverse factorial? 43fan Excel Programming 5 December 30th 03 06:25 PM


All times are GMT +1. The time now is 07:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"