VBA and Macros: practice exercises
A hands-on introduction to VBA. You read short macros that work with Range and Worksheet objects, loops, conditions and events, and reproduce their results with formulas. Each task focuses on understanding what a piece of code does, so you know what a macro does before you trust it. Aimed at Excel users who repeat the same steps daily and want to automate them.
13 exercises · level: Expert
Start with the first task Study the course: VBA and Macros →
Showing 13 of 13
Language Basics
In C2:C6, get what the macro writes with Int(m / 12): the full years of tenure.
In D2:D6, get the result of m Mod 12: how many months are left over beyond the full years.
In E2:E6, build the label as in the last line of the loop, for example "Emma: 2 yr 3 mo". The & operator is the same in Excel as in VBA.
In D2:D7, write what the macro writes: "Overdue" if the due date is earlier than the date in F1, otherwise "On time".
In F2, get the value of the cnt counter: how many invoices are overdue.
In F3, get total: the sum of the overdue invoices.
Reliable Code
In D2:D7, calculate the average order value (revenue / orders), and where the division is impossible, write "no data", like the macro.
In G1, get what the macro's last line writes with WorksheetFunction.CountIf: the number of rows with no data.
Project
In D2:D9, get what the first line of the loop writes: price x quantity.
In E2:E9, get the category from the If block: "Large" when the total is 10,000 or more, otherwise "Regular".
In H1, get the value of the total variable after the loop.
In H2, get the value of the bigCount counter.
In H3, get what WorksheetFunction.Max returns for the totals column.
No exercises match these filters.