Skip to content Skip to sidebar Skip to footer
Blogger Jateng

Excel VBA Userform to Calculate Age and BMI

Excel VBA Userform to Calculate Age and BMI



http://www.onlinepclearning.com Excel VBA Userform to Calculate Age and BMI

In this tutorial I will demonstrate how to perform Calculations in a Userform. 

We will be calculating the age and the BMI from the values entered into the userform

This Video Published Since or about 4 years ago ago, Hosted by youtube.com and Published by Channel: Online PC Learning

Excel VBA Userform to Calculate Age and BMI's Video From Online PC Learning have lenght about 9:00 and was viewed more than 9398 and is still growing

BMI and Age Calculator Step by Step

Adding and creating the Worksheet formulas

Note: once you add these formulas to the worksheet click on the cell but confirm that you simply paste the formula into the formula bar at the highest , then hit enter.

This formula will calculate the age difference between the date added and today.
Formula for Cell G8
=DATEDIF(F8,TODAY(),"Y")&" Years, "&DATEDIF(F8,TODAY(),"YM")& " Months, "&DATEDIF(F8,TODAY(),"MD")&" Days"
Here is the formula to calculate our BMI from the values that have been sent from the userform.
Formula for Cell H11
=G11/((F11/100)*(F11/100))

Formulating the User form

Make sure that you simply have watched the video and make the User form as shown within the illustration above. Notice the names for the textboxes and command buttons.

You will got to use these exact names for the code that you simply are going to be later adding to the User form to figure .

This User form thus consists of

6 labels
5 text boxes
2 command buttons

Properties for the Userform

Note: There are a few of things that you simply can do with the User form which will make it user friendly.

1. Name it appropriately (does not matter what name you select but something like frmAge would be suitable.

2. Add a caption to explain what action this Userform are going to be achieving. like “Age and BMI Calculator”

Adding the VBA code to the Userform

Here is that the code for the Userform. Double click inside the Userform then copy the code below and paste into the Visual Basic editor.

Option Explicit
Private Sub cmdCalculate_Click()
'Declare the variables
Dim AddAge As Long
Dim MyAge As Range
Dim BMI As Range
'Set the the result range
Set MyAge = Sheet1.Range("G8")
'Variable for result
Set BMI = Sheet1.Range("H11")
'Check for DOB value
If IsDate(Me.txtDOB.Value) And Me.txtDOB.Value <> 0 Then
'Add date of birth to worksheet
Sheet1.Range("F8") = Me.txtDOB.Value
'Show formula result in a message box
Me.txtAge.Value = MyAge.Value
Else
MsgBox "You need to add a proper date"
txtDOB.Value = ""
Exit Sub
End If
'Check for Height value and add value
If IsNumeric(txtHeight) And txtHeight <> 0 Then
Sheet1.Range("F11") = Format(Me.txtHeight.Value, "###0.0")
Else
MsgBox "You must add a Height"
Exit Sub
End If
'Check for Weight value and add value
If IsNumeric(txtWeight) And txtWeight <> 0 Then
Sheet1.Range("G11") = Format(Me.txtWeight.Value, "###0.0")
Else
MsgBox "You must add a Weight"
Exit Sub
End If
'Show the BMI result
Me.txtBMI = BMI
Me.txtBMI.Value = Format(BMI, "#,##0.0")
End Sub

Private Sub cmdClose_Click()
Unload Me
End Sub

Run the Userform

In the Assorted module to your VBA editor add the code below.
Right Click the form on the worksheet then choose Assign Macro and assign the macro below. this may call the user form.

Sub Showme()
frmAge.Show
End Sub

In conclusion

I hope you've got enjoyed this tutorial to point out how you'll do calculations during a User form quite simply. i will be able to demonstrate creating a Bonus calculator for workers in our next tutorial.

Related Video with Excel VBA Userform to Calculate Age and BMI

BMI Calculator: How to Calculate Your Body Mass Index Online Easily for Free

BMI Calculator: How to Calculate Your Body Mass Index Online Easily for Free
Melt Away 8 to 16 Pounds (4 to 8 kgs) of Stubborn Body Fat in Just 14 Days! 

FREE VIDEO: http://masteryera.com/2weekdiet BMI Calculator Website: http://RW.lazarangelov.diet Myfitnesspal: https://www.myfitnesspal.com 

CHECK OUT MY DIGITAL BOOKS: Weight Loss: Beginner’s Guide: http://amzn.to/2DB7cyj Habits for High Performance: https://amzn.to ...
 

This Video Published Since 11 months ago ago, Hosted by youtube.com and Published by Channel: Dr. Sam Robbins

BMI Calculator: How to Calculate Your Body Mass Index Online Easily for Free's Video From Mastery Era have lenght about 15:39 and was viewed more than 317 and is still growing


Free BMI (Body Mass Index) Calculator

Free BMI (Body Mass Index) Calculator
www.HealthCalculators.net/BMI

This Video Published Since 2 years ago ago, Hosted by vimeo.com and Published by Channel: Dr. Sam Robbins

Free BMI (Body Mass Index) Calculator's Video From Dr. Sam Robbins have lenght about 00:47 and was viewed more than 9844 and is still growing


BMI Calculator For Women And Men & What is BMI ?

BMI Calculator For Women And Men & What is BMI ?
Both women and men can calculate your BMI (body mass index) by visiting http://www.kidandparent.in/gettingpregnant/bmicalculator What is BMI Index? 

BMI (Body Mass Index) is a method used to calculate your optimal weight based on your height for both men and women. Let us say, you are 160 cms tall and your weight is 45 kgs then to calculate BMI ...

This Video Published Since 6 years ago ago, Hosted by youtube.com and Published by Channel: KidandParent

BMI Calculator For Women And Men & What is BMI ?'s Video From KidandParent have lenght about 1:05 and was viewed more than 90853 and is still growing


Calculate BMI Body Mass Index in MS Access

Calculate BMI Body Mass Index in MS Access
I answer to this Thread on Access World Forums:- http://www.access-programmers.co.uk/forums/showthread.php?p=1483297#post1483297 More Hints And Tips on my Website "Nifty Access" HERE:- http://www.niftyaccess.com Join my Facebook Group MS Access Hints And Tips HERE:- https://www.facebook.com/groups/MS.Access.Hints.And.Tips Subscribe to My ...

This Video Published Since 3 years ago ago, Hosted by youtube.com and Published by Channel: Tony Hine

Calculate BMI Body Mass Index in MS Access's Video From Tony Hine have lenght about 2:50 and was viewed more than 786 and is still growing

Post a Comment for "Excel VBA Userform to Calculate Age and BMI"