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.

Opening USerForm to Create a Body Mass Index Calculator in Excel Using VBA

  • Click on the UserForm option from the Insert option.

Selecting UserForm to Create a Body Mass Index Calculator in Excel Using VBA

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

  • Go to View > Properties Window options.

Editing to Create a Body Mass Index Calculator in Excel Using VBA

  • Make the desired changes in the properties dialog box.

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

UserForm to Create a Body Mass Index Calculator in Excel Using VBA

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

Opening Toolbox to Create a Body Mass Index Calculator in Excel Using VBA

  • Select the label option in the Toolbox dialog box.

Selecting Label option to Create a Body Mass Index Calculator in Excel Using VBA

  • You will get the below result.

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

Editing to to Create a Body Mass Index Calculator in Excel Using VBA

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

  • You will get the below result.

Result to Create a Body Mass Index Calculator in Excel Using VBA

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

Add Label to Create a Body Mass Index Calculator in Excel Using VBA

  • 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.

Adding Text to Create a Body Mass Index Calculator in Excel Using VBA

  • You will get the below result.

Adding text to Create a Body Mass Index Calculator in Excel Using VBA

  • Repeat the previous step again.

Result to Create a Body Mass Index Calculator in Excel Using VBA

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

Inserting Pointer Button to Create a Body Mass Index Calculator in Excel Using VBA

  • 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.

View COde Make the desired changes and you will have the desired result.

  • 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

Insering CodeMake the desired changes and you will have the desired result.

  • 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!
Taryn Nefdt
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.

2 Comments

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo