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()
Unload frmBMICalculator
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.

Download the Free Calculator
You can download the free calculator from here.
<< Go Back to BMI | Formula List | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!


Wonderful!
Thank you so much.