Answers for "excel vba greatest common denominator"

VBA
4

excel vba greatest common denominator

'VBA function to find the Greatest Common Denominator of two numbers:

Function GCD(ByVal a, ByVal b)      '<--Euclid's algorithm
    a = Abs(a): b = Abs(b)
    While b
        If a > b Then a = a - b Else b = b - a
    Wend
    GCD = a
End Function
    
'------------------------------------------------------------------------------
    
MsgBox GCD(15, 20)          '<--displays: 5
    
    
'Note: the GCD() worksheet function is also available but requires the 
'slow call to the worksheet calcuation engine:
      
MsgBox WorksheetFunction.GCD(15, 20)
Posted by: Guest on May-18-2020

Code answers related to "excel vba greatest common denominator"

Code answers related to "VBA"

Browse Popular Code Answers by Language