Thursday, May 6, 2010

Calculating BMI :-

The formula for calculating BMI is

BMI=wieght(/(height2)

Here is the VBA code:-

Private Sub Calc_BMI()
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

No comments: