In this article, we have explained how to Calculate Ratio between two number in Excel. We have used the Excel formula as well as the User defined function in VBA to calculate the RATIO in Excel
RATIO is used to compare two values with each other. In the Excel we don’t have the single function to calculate the ratio.
We have used GCD function of excel to get the Ratio between two numbers. GCD returns the greatest common divisor between two or more numbers.
Below is the formula which we have used to calculate the Ratio in Excel:
=B2/GCD(B2:C2) & " : " & C2/GCD(B2:C2)
We have also created a User defined function in VBA to calculate the Ratio in Excel. Below is the code-
Function RATIO(first_number As Long, second_number As Long) As String Application.Volatile Dim gcd As Long gcd = Application.WorksheetFunction.gcd(first_number, second_number) RATIO = first_number / gcd & " : " & second_number / gcd End Function
After putting this UDF in the module of Visual Basic Editor, you can put the RATIO function in Excel-
=Ratio(B2,C2)
Click here to download the practice file.
Watch the step by step video tutorial:
Visit our YouTube channel to learn step-by-step video tutorials