Level 1 project: fill in an invoice with macros
To finish level 1 you build three macros that complete an invoice between them: work out the amounts and totals, fill in the header with the next invoice number and a due date, and add the right payment note at the bottom. Everything you need, you already know.
You need: Range and Cells, variables, operators and joining text, If Then Else and MsgBox.
The situation
A small electrical wholesaler writes its invoices in Excel. The template never changes: a header with invoice number, date, customer and payment terms, three lines with quantity and price, then net, tax and total, and a payment note at the bottom. Next to the invoice sit three admin values: the last invoice number used, the customer's credit limit and the tax rate.
So far someone types it all by hand, checks the sums on a calculator and now and then forgets to move the number on. Macros should take that over. To keep each piece easy to check, you build three small macros instead of one big one.
The project
Part 1: lines and totals
Numbers first. Each line is quantity times price, net is the sum of the lines, tax is net times the rate in G5, and the total is both together. The tax rate sits in a cell so the same macro works for 20% VAT or a local sales tax rate. The macro writes finished numbers, not formulas. Watch the order: a line can only use values that are already in the cells.
Task Part 1: work out the lines and the totals. D11 to D13 each get quantity times price, D15 the sum of the three amounts (net), D16 the tax (net times the tax rate in G5) and D17 the total (net plus tax). Write numbers into the cells, not formulas.
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Invoice | ||||||
| 2 | |||||||
| 3 | Invoice no. | Last invoice no. | 1043 | ||||
| 4 | Date | Credit limit | 5,000 | ||||
| 5 | Customer | Hoffman Electrical Ltd | Tax rate | 20.00% | |||
| 6 | Customer type | Regular | |||||
| 7 | Payment terms (days) | ||||||
| 8 | Due date | ||||||
| 9 | |||||||
| 10 | Item | Qty | Price | Amount | |||
| 11 | LED panel 2 x 2 ft | 4 | 89.00 | ||||
| 12 | Breaker panel | 2 | 249.50 | ||||
| 13 | Cable trunking 6 ft | 10 | 14.50 | ||||
| 14 | |||||||
| 15 | Net | ||||||
| 16 | Tax | ||||||
| 17 | Total |
Part 2: the invoice header
Now the header. The new invoice number is the last one plus 1, and the new number has to go back into the admin cell, or the next invoice gets the same one. The date is today. Regular customers get 30 days to pay, everyone else 14, and that gives you the due date. In the exercise, "today" is fixed at 16 Mar 2026 so the result can be checked.
Task Part 2: fill in the invoice header. B3 gets the next invoice number (last number from G3 plus 1), and G3 keeps that new number. B4 is today's date. The payment terms in B7 are 30 days for regular customers (B6 = "Regular"), otherwise 14. B8 is the due date: date plus payment terms.
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Invoice | ||||||
| 2 | |||||||
| 3 | Invoice no. | Last invoice no. | 1043 | ||||
| 4 | Date | Credit limit | 5,000 | ||||
| 5 | Customer | Hoffman Electrical Ltd | Tax rate | 20.00% | |||
| 6 | Customer type | Regular | |||||
| 7 | Payment terms (days) | ||||||
| 8 | Due date | ||||||
| 9 | |||||||
| 10 | Item | Qty | Price | Amount | |||
| 11 | LED panel 2 x 2 ft | 4 | 89.00 | 356.00 | |||
| 12 | Breaker panel | 2 | 249.50 | 499.00 | |||
| 13 | Cable trunking 6 ft | 10 | 14.50 | 145.00 | |||
| 14 | |||||||
| 15 | Net | 1,000.00 | |||||
| 16 | Tax | 200.00 | |||||
| 17 | Total | 1,200.00 |
Part 3: payment note and wrap-up
Last comes the note below the invoice. If the total is above the customer's credit limit, the customer has to pay up front. Otherwise the note states the payment terms, using the number from the header. Finally the macro reports that the invoice is ready.
Task Part 3: the note below the invoice. If the total (D17) is higher than the customer's credit limit (G4), write "Prepayment: please pay before delivery." to A19. Otherwise write "Payment due within 30 days.", with the payment terms from B7 instead of 30. Finally the macro shows "Invoice 1044 is ready." with the number from B3.
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Invoice | ||||||
| 2 | |||||||
| 3 | Invoice no. | 1044 | Last invoice no. | 1044 | |||
| 4 | Date | 16 Mar 2026 | Credit limit | 5,000 | |||
| 5 | Customer | Hoffman Electrical Ltd | Tax rate | 20.00% | |||
| 6 | Customer type | Regular | |||||
| 7 | Payment terms (days) | 30 | |||||
| 8 | Due date | 15 Apr 2026 | |||||
| 9 | |||||||
| 10 | Item | Qty | Price | Amount | |||
| 11 | LED panel 2 x 2 ft | 4 | 89.00 | 356.00 | |||
| 12 | Breaker panel | 2 | 249.50 | 499.00 | |||
| 13 | Cable trunking 6 ft | 10 | 14.50 | 145.00 | |||
| 14 | |||||||
| 15 | Net | 1,000.00 | |||||
| 16 | Tax | 200.00 | |||||
| 17 | Total | 1,200.00 |
What matters
Read everything from the cells
All three parts are also checked with other data: other quantities and prices, a different tax rate, a different last number, a new customer, a lower credit limit. If you type 1000 as net or 1044 as the number into the code, Check catches it. The only fixed values in the code should be rules that hold for every invoice: the 30 and 14 days and the texts.
The order of the lines
A macro runs from top to bottom. If you work out the tax before net is in D15, it uses an empty cell, which counts as 0. The same goes for the due date, which needs both the date and the payment terms. Note down what depends on what before you start.
Calculating with dates
To Excel a date is a running number. Date + 30 is therefore simply the day 30 days later, across month ends. The cell's number format makes it show up as a date.
Building text
The payment note has a number in the middle of a sentence. Use & to join three parts: fixed text, the value from B7, fixed text again. The spaces around the number belong inside the quotes.
If it does not work
- If part 1 reports 0 in D16 where 200 is expected, your macro works out the tax before net is in D15. Swap the lines.
- If part 2 says G3 still holds 1043, the step that writes the new number back to G3 is missing.
- If B7 shows 14 instead of 30 for a "Regular" customer, your If compares with text spelled differently. The comparison is case-sensitive.
- If B8 is empty or 0, the due date is calculated before the date and the payment terms are set.
- If the note in part 3 reads "Payment due within30days.", the fixed text pieces are missing their spaces.
- "It works on the visible data but not when checked with other data" means a result is typed into the code somewhere, such as the tax rate, the number in the message or a note chosen without If.
What you learned in level 1
You write macros in the VBA editor, read and clean up recorded code, address cells and ranges with Range and Cells, declare variables with the right type, calculate and join text, ask questions with MsgBox and InputBox, and let the macro decide with If. What is still missing is repetition. The invoice had exactly three lines and you wrote a separate statement for each. With 30 lines, or a list whose length you do not know, that no longer works. That is what level 2 is about.
FAQ
Is the project free?
Yes. All of level 1 is free, the project included. From level 2 on, projects are part of Premium.
How many points is the project worth?
Each of the three parts counts 15 points instead of the usual 10, because you have to combine several steps.
Can I write formulas instead of numbers?
Part 1 asks for numbers because it is about calculating in VBA. Check looks at the result in each cell, so formulas with the right result pass as well. For a real invoice, fixed numbers make sense anyway: an invoice that has been sent should not change any more.
Why is the tax not rounded to cents?
The exercise leaves rounding out so it stays about the calculation steps. On a real invoice you round the tax to two decimals. How rounding works in VBA, and where it differs from Excel, is covered in Operators.