|
|
Body
Mass Index (BMI) is so popular today that it has become a standard measure for
our health status. If your BMI is too high, it means you are overweight and
would likely face a host of potential health problems associated
with high BMI, such as hypertension, heart disease, diabetics and many others. I
have programmed a BMI calculator using VB6 professional, but now I will show you
how to create a VBA BMI calculator in MS Excel.
Private Sub CommandButton1_Click()
Dim weight, height, bmi, x As Single
weight = Cells(2, 2)
height = Cells(3, 2)
bmi = (weight) / height ^ 2
Cells(4, 2) = Round(bmi, 1)
If bmi <= 15 Then
Cells(5, 2) = "Under weight"
ElseIf bmi > 15 And bmi <= 25 Then
Cells(5, 2) = "Optimum weight"
Else
Cells(5, 2) = "Over weight"
End If
End Sub
|
Explanation:
The formula for
calculating BMI is
BMI=wieght(/(height2)
The function Round
is to round the value to a certain decimal places. It takes the
format Round(x,n), where n is the number to be rounded and n is the
number of decimal places.
The second part of
the program usees the If...Then..Else statement to evaluate the
weight level.
|
|