Returns the greatest common divisor (GCD) of two or more integers. GCD is the largest positive integer that divides each of the numbers without a remainder. Essential for fraction simplification, modular arithmetic, number theory, and mathematical calculations.
Master the fundamentals of Excel GCD function
The GCD function returns the greatest common divisor (also called greatest common factor) of two or more integers. GCD is the largest positive integer that divides each of the numbers without leaving a remainder. Key properties: GCD(a, b) = GCD(b, a) (commutative), GCD(a, a) = a, GCD(a, 0) = |a|, GCD(1, any) = 1, if GCD(a, b) = 1, then a and b are coprime. Essential for fraction simplification, modular arithmetic, number theory, cryptography, and mathematical algorithms (Euclidean algorithm).
GCD(a, b) = GCD(b, a)
Works with 2 or more numbers
GCD = 1 means coprime
Use to simplify fractions
Function-specific parameters
Function-specific return type
Simplify fractions to lowest terms
Mathematical number theory
Calculations in modular arithmetic
Cryptographic algorithms
Exact matching required
Returns numeric position
Handles missing text gracefully
=GCD(number1, number2)First number. Must be an integer.
Additional numbers (up to 255). Must be integers.
The greatest common divisor
Description: Returns the greatest common divisor of two or more integers
GCD of two numbers
Returns 12 because GCD(24, 36) = 12. The largest number that divides both 24 and 36 is 12 (24 = 12×2, 36 = 12×3).
Use GCD function in VBA
' Basic GCD in VBA
Range("C1").Value = Application.WorksheetFunction.Gcd(24, 36)
' Returns: 12
' Calculate GCD
Sub CalculateGCD()
Dim num1 As Integer
Dim num2 As Integer
num1 = Range("A1").Value
num2 = Range("A2").Value
Dim result As Integer
result = Application.WorksheetFunction.Gcd(num1, num2)
Range("B1").Value = result
End Sub
' Calculate GCD of three numbers
Sub CalculateGCDThree()
Dim num1 As Integer
Dim num2 As Integer
Dim num3 As Integer
num1 = Range("A1").Value
num2 = Range("A2").Value
num3 = Range("A3").Value
Dim result As Integer
result = Application.WorksheetFunction.Gcd(num1, num2, num3)
Range("B1").Value = result
End Sub
' Simplify fraction using GCD
Sub SimplifyFraction()
Dim numerator As Integer
Dim denominator As Integer
numerator = Range("A1").Value
denominator = Range("A2").Value
Dim gcd As Integer
gcd = Application.WorksheetFunction.Gcd(numerator, denominator)
Dim simplifiedNum As Integer
Dim simplifiedDen As Integer
simplifiedNum = numerator / gcd
simplifiedDen = denominator / gcd
Range("B1").Value = simplifiedNum & "/" & simplifiedDen
End Sub
' Check if numbers are coprime
Sub CheckCoprime()
Dim num1 As Integer
Dim num2 As Integer
num1 = Range("A1").Value
num2 = Range("A2").Value
Dim gcd As Integer
gcd = Application.WorksheetFunction.Gcd(num1, num2)
If gcd = 1 Then
Range("B1").Value = "Coprime"
Else
Range("B1").Value = "Not Coprime (GCD = " & gcd & ")"
End If
End SubSimplify fractions to lowest terms
Mathematical number theory calculations
Calculations in modular arithmetic
Cryptographic algorithms
GCD returns #NUM! for non-integers or negative numbers
=GCD(ABS(INT(A1)), ABS(INT(A2)))Solution: GCD only works with positive integers. Negative numbers are converted to absolute values. Decimals are truncated. Ensure inputs are positive integers.
Non-numeric input in GCD
=GCD(VALUE(A1), VALUE(A2))Solution: Ensure all inputs are numeric. GCD requires numbers. Check for text, errors, or empty cells. Use VALUE() if needed.
GCD(0, 0) returns error
Ensure at least one non-zero numberSolution: GCD(0, 0) = #NUM!. At least one number must be non-zero. GCD(n, 0) = n for n > 0.
How to use GCD to simplify fractions
=A1/GCD(A1,A2) & "/" & A2/GCD(A1,A2)Solution: To simplify a/b: GCD = GCD(a, b), simplified = (a/GCD) / (b/GCD). Example: 24/36, GCD(24,36)=12, so 24/36 = 2/3.