# How to Create a Body Mass Index Calculator in Excel Using VBA (Step-by-Step)

### Step 1 – Creating a UserForm

• Go to Developer > Code > Visual BasicÂ options.

• Click on the UserForm option from the InsertÂ option.

• You will get the desired form, like the below image.

• Go to View > Properties WindowÂ options.

• Make the desired changes in the properties dialog box.

• You will get the below result after the desired changes.

• Select the Toolbox option to open the Toolbox dialog box.

• Select the label option in the Toolbox dialog box.

• You will get the below result.

• Select the label, click the Properties Window option, and make the desired changes.

• Change Font, Font Styles, and Size, and press OK.

• You will get the below result.

• Select the label option from the Toolbox dialog box again.

• You will get a label option like the previous step and make the desired changes here.

• You will get the below result.

• Select the Text option in the Toolbox dialog box.

• You will get the below result.

• Repeat the previous step again.

• Go to the Pointer option in the Toolbox dialog box and you will have the desired result.

• Make the desired changes and you will have the desired result.

### Step 2 – Using a VBA Code:

• Right-click the Click to See Your BMI option and select the View CodeÂ option.

• Insert the VBA code:
``````Private Sub cmdCalculate_Click()
Dim weightOne As Double
Dim heightOne As Double
Dim bmiCalc As Double
If optMetric.Value = True Then
Let weightOne = CDbl(txtWeight.Value)
Let heightOne = CDbl(txtHeight.Value)
bmiCalc = (weightOne) / (heightOne) ^ 2
bmiCalc = Format(bmiCalc, "0.0")
Let txtBMI.Value = bmiCalc
End If
If optCust.Value = True Then
Let weightOne = CDbl(txtWeight.Value)
Let heightOne = CDbl(txtHeight.Value)
bmiCalc = (weightOne) / (heightened ^ 2) * 703.0704
bmiCalc = Format(bmiCalc, "0.0")
Let txtBMI.Value = bmiCalc
End If
End Sub``````

• Right-click on the Close UseFormÂ option and select View Code.

• Insert the following VBA code:
``````Private Sub cmdCloseUserForm_Click()
End Sub``````

### Step 3 – Inserting a Command Button

• Return to the main worksheet and select Developer > Insert > ActiveX Controls options.

• You will see the below result.

• Right-click on the CommandButton 1 and select the PropertiesÂ option.

• Make the desired changes in the PropertiesÂ option.

• You will see the below result.

• Right-click, select the View Code option, and insert the following VBA code:
``````Private Sub cmdOpenForm_Click()
frmBMICalculator.Show
End Sub``````

• You will see the below result.

### Step 4 – Showing the Final Result

• Insert the Height and Weight.

• Press the Click to see Your BMI option to see the desired result.

<< Go Back to BMI | Formula List | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Taryn Nefdt

Taryn is a Microsoft Certified Professional, who has used Office Applications such as Excel and Access extensively, in her interdisciplinary academic career and work experience. She has a background in biochemistry, Geographical Information Systems (GIS), and biofuels. She enjoys showcasing the functionality of Excel in various disciplines. She has over ten years of experience using Excel and Access to create advanced integrated solutions.