Factorial Problem

Juggler_IN

Active Member
Joined
Nov 19, 2014
Messages
349
Office Version
  1. 2003 or older
Platform
  1. Windows
I want to calculate a value (x) using factorials for any given word (w) as per the following logic:

For example,
if w=BOB then, x = 3!/(2!1!) --- BOB has three letters (3!) with B twice (2!) and O once (1!);
if w=ABE then, x = 3!/(1!1!1!) --- ABE has three letters (3!) with A once (1!), B once (1!), and E once (1!);
if w=ABBA then, x = 4!/(2!2!) --- ABBA has four letters (4!) with A twice (2!) and B twice (2!);

Is there a way to execute and output x for any w input?
 
Or try:
VBA Code:
Public Function My_Factorial(txt As String) As Long
Dim Numerator As Long, Denominator As Long, i As Long, t As String
Numerator = Application.Fact(Len(txt))
Denominator = 1
Do While Len(txt) > 0
    t = Replace(txt, Left(txt, 1), "")
    i = Len(txt) - Len(t)
    Denominator = Denominator * Application.Fact(i)
    txt = t
Loop
My_Factorial = Numerator / Denominator
End Function
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Rick Rothstein he is just GREAT.
That is most kind of you to say, but quite frankly, I do not consider myself to be better than, and hopefully not all that much less than either, the other volunteers in this (or any other forum for that matter)... we all have are various strengths and weaknesses and usually choose to participate in those threads where are strengths are most applicable... that may create a false sense of overall excellence which is not actually warranted.
 
Upvote 0
In many times your answers are not just a code, you take me through the logic, doing that make you fit in the following quote:
give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime

Thank you.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top