Lab12 - Functions - All
Lab12 - Functions - All
1. Download the excel workbook and save it in D Drive. Rename it after Assignment
number and your roll number (e.g. L10-2026-11-001). Save it as macro enabled
workbook! (.xlsm).
2. Create a new worksheet and call it “Group Information” and enter your
information in it similar to the example below:
The idea of making this group work is that you can learn from each other and teach each
other as you go along with your work. Please help your group partners to understand the
concept/logic/syntax and then be each other’s support. Where you need additional help, you
can always reach out to instructor and TAs too.
Functions and more Total Marks = 30
A manager at CleanHome, a cleaning supplies store brand, is working on sales data for one
of their branches and needs your help with VBA.
1. Write a sub procedure called “main” and leave it empty for now. [1]
a. You can use this sub procedure to call and use the functions and sub
procedures you will be creating below.
3. Write a sub procedure called “computeDailySales” [1], that calculates the sale for a
given date. For this:
a. Asks the user the date for which they want the sale. [1]
b. Uses a for-loop to find the column for that date and breaks the loop when
you do. [2+1]
c. Once done, use a do-until loop (this is not to be nested in the previous one,
comes after) to calculate the sale for that day. [3]
i. When calculating the sales for each item, use the ‘findTaxRate’
function created above to get the tax rate for the item. [2]
ii. Daily sale for each item = price * quantity * (1 – (tax rate/100))
d. Display the total sales for the day in the corresponding cell in row 13 and
make it bold. [1+1]
e. Insert a button with appropriate name and assign it to the macro. [1]
4. Write a function to find out if the tax rate is low, medium, high or very high. To this:
a. The function will take one argument of the item name[1]
b. Get the tax rate value using the findTaxRate function[1]
c. Use a switch statement (select case, see in key below) to define different
cases based on the following: [2]
i. Less than 5 is low
ii. Less than 10 is medium
iii. Less than 15 is high
iv. Above that is very high
d. Use the function directly in excel worksheet in column c and display the
answers. [1]
Do While test-expression
Statement to execute
Statement to execute
updater (updates test value to false to stop looping)
Loop
Do-Until loop – performs iterations only while a conditional test made on each
iteration evaluates as False.
Do Until test-expression
Statement to execute
Statement to execute
Updater (updates test value to true to stop looping)
Loop