View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Karl E. Peterson Karl E. Peterson is offline
external usenet poster
 
Posts: 22
Default reducing a fraction

GreenMonster wrote:
Is there a functions that will reduce a fraction in a cell?


I'm not aware of one, but then I'm not very "up" on the Excel object model either.
From a VB(A) perspective, this is something you can certainly code up, though. Take
a look at http://vb.mvps.org/samples/Fraction for a drop-in ready class that handles
rational numbers. Really, all you need is the GCD:

Private Function Gcd(ByVal a As Long, ByVal b As Long) As Long
' Find greatest common denominator.
If (b = 0) Then
Gcd = a
Else
Gcd = Gcd(b, a Mod b)
End If
End Function

You might like the class, though, as it supports all sorts of other fractional fun.
--
Working Without a .NET?
http://classicvb.org/petition