Option Explicit Function EuclidGCD(a As Variant, b As Variant) As Long ' GCD = Greatest Common Divisor (in GE: GrӇter gemeinsamer Teiler) ' LCM = Least Common Multiple (in GE: Kleinstes gemeinsames Vielfaches) ' Apparently, good old Euclid came up with this theorem: ' GCD(A,B)=GCD(B,A Mod B) ' which in VBA looks like this: ' Source: Knuth D. E., Seminumerical Algorithms, vol. 2 of The Art of Computer Programming ' Addison-Wesley, 1973 ' as found at ' VBA coding and wrapping by Michael Bednarek, July 2004 http://mbednarek.com/ If b = 0 Then EuclidGCD = a Else EuclidGCD = EuclidGCD(b, a Mod b) End If End Function '==================== Function myGCD(a As Variant) As Long ' Wrapper to pass elements of an array to EuclidGCD [mb@tgm.com.au] Dim i As Long Dim x As Long x = EuclidGCD(a(LBound(a)), a(LBound(a) + 1)) For i = LBound(a) + 1 To UBound(a) x = EuclidGCD(a(i), x) Next i myGCD = x End Function '==================== Sub testmyGCD() ' Test the function myGCD() Dim a() As Variant a = Array(n1, n2, ...) ' You populate it Debug.Print myGCD(a) End Sub '==================== Function EuclidLCM(a As Variant, b As Variant) As Long ' As for LCM, Euclid observed that: ' LCM(A,B)=A * B / GCD(A, B) ' which in VBA looks like this: ' Source: Knuth D. E., Seminumerical Algorithms, vol. 2 of The Art of Computer Programming ' Addison-Wesley, 1973 ' as found at ' VBA coding and wrapping by Michael Bednarek, July 2004 http://mbednarek.com/ EuclidLCM = a * b / EuclidGCD(a, b) End Function '==================== Function myLCM(a As Variant) As Long ' Wrapper to pass elements of an array to EuclidGCD() [mb@tgm.com.au] Dim i As Long Dim x As Long x = EuclidLCM(a(LBound(a)), a(LBound(a) + 1)) For i = LBound(a) + 1 To UBound(a) x = EuclidLCM(a(i), x) Next i myLCM = x End Function '==================== Sub testmyLCM() ' Test the function myLCM() Dim a() As Variant a = Array(n1, n2, ...) ' You populate it Debug.Print myLCM(a) End Sub '====================