Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.






Panel
borderColor#dfe1e5
bgColor#eff9ff
borderWidth2
titlePage content

Table of Contents


Beginner

In the first exercise, we will focus on variables and some calculations. This is a nice follow up to the Hello world tutorial in Beginner tutorials on VBA.

Expand
titleExercise 1: BMI


Column
width60

Body mass index (BMI) is a value derived from the mass (weight) and height of a person. It is a convenient rule of thumb used to broadly categorize a person as underweightnormal weightoverweight, or obese.

The BMI is defined as



Your task is to create a sheet where you can calculate your BMI by entering your name, height and weight. The calculated BMI should be displayed by the click of a button. A draft to a finished solution is shown below.

Image RemovedImage Added


Column
width40

Commonly accepted BMI ranges are:


BMI [kg/m2]

Underweight< 18.5
Normal weight18.5 - 25
Overweight25 - 30
Obese> 30



Expand
titleSolution: BMI


Info

There are as always a number of ways to solve this task, so don't be alarmed if your answer differentiates from our solution.


Info

Make sure you have enabled the Visual Basic shortcut in Excel, as this is used in the video. If you have not, click this link.


This solution is currently available as a go-through video: BMI VBA (no audio) and as the finished solution: BMI exercise.xlsm

Further documentation on functions used:

Expand
titleExtra tasks (no solution yet)
  • To make the answer more informative to the user, we may in addition to the BMI value add the corresponding BMI range (normal weight, underweight etc.). How can we do this?






BibTeX Display Table