You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 40 Next »








Page content

Beginner

Exercise 1

In the first exercise, we will focus on variables and some calculations using arithmetic operators.


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.

Commonly accepted BMI ranges are:


BMI [kg/m2]

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

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


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:

  • 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?
  • If we were to store statistics of every calculated BMI in every range, how may we do this?
  • How could we do the same task without the use of VBA, but only using Excel commands? Is that a better approach to this exact problem, and if so, why?

Exercise 2

In this exercise it is recommended to use the Record macro-feature available in VBA, although you don't necessarily have to.

Make a macro that deletes all but the first sheet. The macro should not take into consideration if any sheets are written on. Some pictures showing before and after running the desired macro are presented below.




  • No labels