Free VBA Tutorial β learn Excel macros in 12 days
Loops, ranges, functions and formatting - topic by topic, with every macro runnable right here in the page against a real worksheet.
A free, hands-on VBA course
Twelve short lessons that take you from never having opened the Visual Basic Editor to writing a macro that builds a report on its own. Every macro runs in your browser against a real worksheet - edit it, break it, run it again. Nothing to install, no signup, and you do not even need Excel in front of you.
Start with Day 1.
The 12 days
Day 1 β What VBA is, and your first macro
VBA is how you stop doing the same Excel job by hand every week. Day one is the whole shape β¦Day 2 β Variables, types and Option Explicit
A variable is a named box. Getting the name and the type right is most of what separates codβ¦Day 3 β Cells, Range and Offset
Two ways to point at a cell, and knowing which to use when is what makes a macro readable.β¦Day 4 β If, ElseIf and Select Case
Code that always does the same thing is a formula. Code that decides is a macro.β¦Day 5 β For loops - doing it to every row
This is the day VBA starts earning its keep. One loop replaces an afternoon of dragging formβ¦Day 6 β The last row, Do loops and For Each
Hard-coding row 17 works until somebody adds row 18. This is the day your macros stop breakiβ¦Day 7 β Text functions - cleaning messy data
Most of the data you will ever automate arrives dirty. These eight functions fix nearly all β¦Day 8 β Numbers, rounding and dates
Two things break reports more than anything else: a rounding rule nobody checked, and a dateβ¦Day 9 β Subs, Functions and arguments
One 200-line Sub is a nightmare to fix. Six small ones that each do one thing is a program yβ¦Day 10 β Arrays, and why they make macros fast
This is the difference between a macro that takes four minutes and the same macro taking undβ¦Day 11 β Formatting, With blocks and WorksheetFunction
The calculation is only half the job. A report nobody can read gets sent back.β¦Day 12 β Practice questions and interview answers
Everything from the first eleven days, as problems. Try each one before you look.β¦The worksheet everything runs against
Sixteen orders in A1:G17. Column H is deliberately empty - filling it is the first real job you will do, on Day 2.
What this playground can and cannot do
The VBA language is a language, so it runs here for real. The interpreter is written from scratch and handles variables and types, If / ElseIf / Select Case, For / For Each / Do / While loops with Exit, Subs and Functions with arguments including ByRef and ByVal, one- and two-dimensional arrays, and the string, number and date functions you use every day.
The worksheet is real too: Cells and Range, .Value, .Offset, .Resize, .End(xlUp), .Rows.Count, .Font.Bold, .Interior.Color, .NumberFormat, With blocks, and WorksheetFunction for Sum, Average, Max, Min, Count, CountA, CountIf, SumIf, Round, Proper and VLookup. Reading a block into a 2-D array with arr = Range("A2:G17").Value works, and so does writing one back.
After each run the sheet is redrawn with every cell your macro changed outlined in gold, so you can see exactly what happened.
How to get the most out of it
- Type the code, do not copy it. The typing is where the learning happens, and the typos teach you to read error messages.
- Change something and run it again. Every box is editable. Break it on purpose.
- Watch the gold cells. If your macro changed a cell you did not expect, find out why before moving on.
- Do the exercises at the end of each day before you go to the next one.
