Level 5 project: customer sales report

To finish level 5 you build the kind of report a sales team needs every month: a long list of individual sales turns into a short summary per customer. The macro reads the data in one step, groups it with a Dictionary and copes with messy data and last month's leftovers.

You need: arrays (reading a range into an array), the Dictionary (totals per key), error handling, and from levels 3 and 4 working with worksheets and sorting. When something goes wrong, stepping through helps.

The situation

An office supplies wholesaler exports its sales from the order system every month: one row per sale with date, customer and amount. The sales manager wants to know how much revenue each customer brought in and how often they ordered. Until now someone builds a PivotTable for it every month and copies the result into the report. A macro should take over and run each month without any manual fixing.

The list gets longer or shorter from month to month, and new customers appear. Fixed row numbers or customer names in the code will fail: every part is also checked against different data.

The project

Part 1: sales per customer

The results sheet already exists, headings included. Read the raw data into an array with one assignment and add up with a Dictionary. Note that the active sheet is not the data sheet: every cell needs its sheet in front.

Task The Sales sheet holds this month's sales, and customers appear more than once. The macro CustomerTotals should write sales per customer to the Summary sheet: from row 2, the customer in A and the total in B, in the order the customers first appear. Read the raw data (A2 to C of the last row) into an array and add up with a Dictionary. The active sheet is Summary while the data sits on Sales, so address every cell through wsData or wsOut.

Summary

ABCD
1CustomerSales
2
3
4
5

Sales

ABCD
1DateCustomerAmount
22 Mar 2026Carter Bakery420.00
33 Mar 2026Peters Motors1,850.00
44 Mar 2026Lakeview Hotel960.00
56 Mar 2026Carter Bakery315.50
67 Mar 2026Brandt Electrical2,240.00
79 Mar 2026Peters Motors730.00
810 Mar 2026Carter Bakery188.00
913 Mar 2026Lakeview Hotel1,405.00
1014 Mar 2026Brandt Electrical610.00
1116 Mar 2026Peters Motors990.00

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

Part 2: customer list on a new sheet

Now the macro adds the results sheet itself, also counts the orders per customer and sorts the list by sales. Two Dictionaries with the same keys hold the count and the total.

Task This time the Summary sheet does not exist yet. The macro CustomerList adds it after the last sheet and writes the headings Customer, Orders, Sales in row 1. Below that, one row per customer with the number of orders and the sales total, sorted by sales with the largest at the top. Read the raw data into an array again and use two Dictionaries, one for counting and one for adding up.

ABCD
1DateCustomerAmount
22 Mar 2026Carter Bakery420.00
33 Mar 2026Peters Motors1,850.00
44 Mar 2026Lakeview Hotel960.00
56 Mar 2026Carter Bakery315.50
67 Mar 2026Brandt Electrical2,240.00
79 Mar 2026Peters Motors730.00
810 Mar 2026Carter Bakery188.00
913 Mar 2026Lakeview Hotel1,405.00
1014 Mar 2026Brandt Electrical610.00
1116 Mar 2026Peters Motors990.00

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

Part 3: ready for every month

This month's export is messy, and the results sheet still holds last month's report with more customers than this time. The macro clears up first, skips amounts that are not numbers, says at the end how many rows it skipped, and reports unexpected errors in plain words.

Task New month, new raw data, and it is messy: some amounts are text such as "n/a" or "tbc". The Summary sheet still holds last month's result. The macro CustomerReport should 1. clear the old rows below the heading, 2. write each customer's new sales total to A and B (in raw-data order), skipping rows without a number, 3. finish with exactly the message "Done: 2 rows skipped" (the number from the run). Also add error handling with On Error GoTo that reports "Error: " plus Err.Description on any unexpected error.

Sales

ABCD
1DateCustomerAmount
22 Apr 2026Carter Bakery510.00
33 Apr 2026Peters Motors2,120.00
45 Apr 2026Lakeview Hoteln/a
56 Apr 2026Carter Bakery274.50
69 Apr 2026Brandt Electrical1,890.00
710 Apr 2026Peters Motorstbc
812 Apr 2026Lakeview Hotel1,365.00
913 Apr 2026Carter Bakery199.00

Summary

ABCD
1CustomerSales
2Peters Motors3570
3Brandt Electrical2850
4Lakeview Hotel2365
5Carter Bakery923.5
6Vogt & Partners1655
7Corner Café412

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

What matters

Read, then calculate, then write

Split the macro into these three sections. The sheet is read only at the start and written only at the end, and everything in between happens in memory. That is faster and easier to check: with a breakpoint after the totals, the Locals window shows the whole Dictionary before a single cell has changed.

Array columns count from 1

If you read Range("A2:C" & lastRow), column 1 of the array is the date, column 2 the customer and column 3 the amount, and row 1 of the array is row 2 of the sheet. If you read from A1 with CurrentRegion, row 1 of the array is the heading and the loop starts at 2.

Every cell with its sheet

Cells(r, 1) without a sheet in front always means the active sheet. In part 1 that is the Summary sheet, while the data sits elsewhere. wsData.Cells(...) and wsOut.Cells(...) make it clear where you read and write, whichever sheet is in front.

Clear old results first

A macro that runs every month has to expect whatever the last run left behind. If it writes four customers this time but six were there last time, two old rows stay at the bottom unless you clear them first. Clear only the values below the heading with ClearContents, so the heading and the formats stay.

Check before you catch

Text amounts like "n/a" are to be expected, which is what IsNumeric is for. On Error is for the unexpected: a renamed sheet, a missing range. Without IsNumeric, the error handling in part 3 would kick in and report "Error: Type mismatch", and there would be no report at all.

If it does not work

  • "Summary!A2 is empty" in part 1: the macro writes to the active sheet instead of wsOut, or reads the data from the wrong sheet. Put the sheet in front of every Range and Cells.
  • The customers are right but the order is not (part 2): without sorting, Carter Bakery is at the top because it appears first. Sort by column C, descending, after the output, and pass Header:=xlYes so Excel does not treat the heading as a data row.
  • "Summary!A6 should stay empty" in part 3: last month's rows were not cleared.
  • The final message is different: the text has to match exactly, colon and spaces included. Also check that Exit Sub sits before the error label; without it a second message follows the correct one.
  • Everything is right on the visible data but not in the check: somewhere there is a fixed row number such as A2:C11, or a fixed customer name. Find the last row with End(xlUp).

What you learned in level 5

You keep data in arrays and write whole ranges in one step, group by key with the Dictionary, catch errors on purpose, split macros into procedures with arguments, find bugs by stepping through, and let event macros start on their own. These are the building blocks of almost every larger macro in an office. Level 6 puts them to work on typical real tasks: combining sheets, building reports and sharing macros safely.

FAQ

How many points is the project worth?

Each of the three project tasks counts for more than a single exercise, because you solve several steps together.

Is the project free?

No. Projects from level 2 on are part of Premium. In every level 5 lesson the first exercise is free, so you can prepare without Premium.

Do I have to use a Dictionary?

Yes, parts 1 and 2 require CreateObject and UBound, because the project is meant to practise exactly these building blocks. How you write out the results, with a loop or with Transpose, is up to you. The check looks at the sheet afterwards.

Would a PivotTable not do the job?

For a one-off report, yes. The macro pays off when the same report comes round every month, with checks a PivotTable does not do: counting skipped rows, filling a fixed results sheet that others build on.

Level 5 complete

Next up is level 6, real-world tasks. It starts with combining sheets: pulling data from several sheets, such as one per branch, onto a single summary.

Combine sheets

Write to us

Choose language

Select your preferred language