Вы находитесь на странице: 1из 4

C&PE 121 Spring 2013

Prelab 7

Goals
This lab demonstrates:
Sequential, decision (Select Case) and repetition (For loop) VBA program structures
Documenting VBA code
Using variable defined as Range object in VBA function
Prelab (Total 2 pts)
Complete the problems given in this document. Submit the excel file via the Blackboard prelab assignment for
your section before the start of your lab class. The excel file should be saved as a Macro-Enabled Workbook
and named in the form CPE121_PRELAB7_bsmith. Work each problem on its own worksheet in a single
workbook. Rename Sheet1 and Sheet2 to Problem 1 and Problem 2, respectively. Write your name in
both worksheets in cell A1. Read the full instructions of the problem before you start working on it.
Problem 1 (1 pt)
You are going to create a VBA function that uses the Select Case condition structure to convert temperature
to Kelvin units. The function will only be able to from degree Celsius, Fahrenheit or Rankin to Kelvin. If a
temperature is provided in any other temperature units it displays a message. If a temperature is provided in
Kelvin, the function returns the same value. The user has to provide as argument of the function the
temperature value and units to convert to Kelvin. The flow chart of the procedure is shown below.

1. Insert a VBA Module (Module1) in your workbook, rename it Problem1 and write the code for TKSC
function shown in the following screen shot.

C&PE 121 Spring 2013

Prelab 7

2. Test the function in worksheet Problem 1 as shown in the following screen shot. Also add labels as shown
here.

3. Your worksheet should look like the screen shot below.

C&PE 121 Spring 2013

Prelab 7

Grade Checklist
2.1 (0.1 pts) Student name in worksheet Problem 1, cell A1, and labels as indicated.
2.2 (0.5 pts) TKSC Function code and typed in module Problem1
2.3 (0.3 pts) Function tested in worksheet Problem 1 as instructed.
2.4 (0.1 pts) Function displays correct results.
Problem 2 (1 pt)
You are going to create a VBA function that uses the For repetition structure to calculate the average of a
group of values entered in a range of cells in worksheet Problem 2. The argument of the function is the range
of cells and will be received in a Range object. The flow chart of the procedure is shown below.

1. Add a new module and rename it to Problem2 and type in it the code shown in the following page.
2. Enter the values 1, 2 , 3, 4 and 5 in cells B3 to B7 in worksheet Problem 2, labels and test the
function as shown in the screen shot in the following page.
Grade Checklist
2.1 (0.1 pts) Student name in worksheet Problem 2, cell A1, and labels as indicated.
2.2 (0.5 pts) MyAverageFunction Function code and typed in module Problem2
2.3 (0.3 pts) Function tested in worksheet Problem 2 as instructed.
2.4 (0.1 pts) Function displays correct result.

C&PE 121 Spring 2013

Prelab 7

Вам также может понравиться