Free course · 33 lessons
Free Excel VBA course: learn macros step by step
Automate Excel with VBA. Start with the macro recorder and finish with events, user forms, classes and fast array code. Every lesson has complete code you can paste and run.
Beginner
- 1What is VBA? Macros, when to use them and macro securityLearn what VBA and macros are, when VBA beats formulas or Power Query, how .xlsm files work and how to set macro security safely in the Trust Center.12 min
- 2The Developer tab and the VBA editorShow the Developer tab, open the Visual Basic Editor and learn its windows: Project Explorer, Properties, code window, Immediate window and modules.14 min
- 3The macro recorder: record, read and clean up codeRecord a macro, run it again, read the code Excel wrote, switch to relative references and clean recorded code into short, reliable VBA.15 min
- 4Your first macro: Sub, MsgBox, running it and a buttonWrite a macro from scratch: the Sub structure, MsgBox, comments and line continuation, then run it in five ways and assign it to a button on the sheet.14 min
- 5Variables and data types: Dim, Option Explicit and scopeStore values in variables: Dim, the main VBA data types, Option Explicit, constants, object variables with Set, and procedure, module and public scope.16 min
- 6Range and Cells: working with cells in VBARefer to cells with Range and Cells, read and write values and formulas, use Offset, Resize, CurrentRegion, With blocks, formatting and clearing.18 min
- 7Workbooks and worksheets in VBARefer to workbooks and sheets safely: ThisWorkbook vs ActiveWorkbook, sheet names, index and code names, add, copy, rename, hide and delete sheets.16 min
- 8Making decisions: If, ElseIf and Select CaseTeach your macros to decide: If...Then...Else, ElseIf chains, And/Or conditions, single-line If and Select Case with ranges and Case Is.14 min
- 9For loops: For...Next and For EachRepeat actions with For...Next and For Each: counters, Step, looping backwards to delete rows, looping through cells and sheets, Exit For and nested loops.15 min
- 10Do loops: Do While, Do Until and Exit DoRepeat code until a condition changes with Do While and Do Until, test at the top or bottom, stop runaway loops with Esc or Ctrl+Break and use Exit Do.13 min
- 11Operators and expressions in VBAArithmetic, joining text, comparisons, Like patterns, Is for objects, And/Or/Not, operator precedence and the overflow traps that catch VBA beginners.14 min
- 12Working with text (strings) in VBACut, search, clean and build text in VBA with Len, Left, Mid, InStr, Replace, Trim, Split, Join, Format, StrComp, vbCrLf and Chr, using real data examples.16 min
Intermediate
- 13Working with dates and times in VBAHandle dates safely in VBA: Date, Now, DateSerial, DateAdd, DateDiff, Year/Month/Day, Weekday, Format, date literals and the CDate locale trap.16 min
- 14Talking to the user: MsgBox and InputBoxShow messages and ask questions with MsgBox buttons, icons and return values, get input with InputBox and Application.InputBox, pick ranges, handle Cancel.15 min
- 15Arrays in VBA: static, dynamic and fast range processingStore many values in one variable with VBA arrays: static and dynamic arrays, ReDim Preserve, 2-D arrays and reading a whole range into memory for speed.18 min
- 16Functions and Subs: parameters, ByVal, ByRef and return valuesSplit VBA code into reusable Subs and Functions: pass parameters, understand ByRef vs ByVal, use Optional arguments and return values.16 min
- 17User-defined functions (UDFs): your own worksheet functionsWrite your own Excel functions in VBA and use them in cells like SUM: commission tiers, VAT, text clean-up, error values, spilled arrays and add-ins.17 min
- 18Using Excel worksheet functions in VBACall VLOOKUP, MATCH, SUMIFS and COUNTIF from VBA, handle not-found errors with Application vs WorksheetFunction, use Evaluate and write formulas into cells.15 min
- 19Error handling and debugging in VBAHandle run-time errors with On Error, Err and Resume, clean up safely, and debug with F8 stepping, breakpoints, the Immediate window, Locals and Watches.20 min
- 20Events: macros that run by themselvesMake VBA react automatically with Worksheet_Change, SelectionChange, BeforeDoubleClick, Workbook_Open and BeforeSave, and use EnableEvents safely.18 min
- 21UserForms: build a data-entry form in VBADesign a VBA UserForm with text boxes, combo boxes and buttons, fill it on start-up, validate input and write each entry to the next empty row.20 min
- 22Find, filter and sort data with VBASearch with Range.Find and FindNext, filter lists with AutoFilter, copy only visible rows, sort with SortFields and remove duplicates from VBA.20 min
- 23Find the last row and build dynamic ranges in VBAFind the last used row and column reliably with End(xlUp), CurrentRegion and Find, avoid UsedRange traps, and build ranges that grow with your data.16 min
- 24Excel tables in VBA: working with ListObjectsCreate Excel tables from VBA, add rows, read columns, loop through records, filter, sort, resize and use structured references with the ListObject object.18 min
Advanced
- 25Create and format charts with VBACreate charts with AddChart2 and ChartObjects, set data and chart type, format titles, axes and series, export to PNG and make one chart per region.20 min
- 26Pivot tables with VBA: create, filter and refreshBuild pivot tables from VBA with PivotCaches.Create, add row, column, value and filter fields, hide items, refresh, change the source and read values.22 min
- 27Files and folders: open, save, loop through files and write text filesLoop through every workbook in a folder with Dir, let users pick folders with FileDialog, save as .xlsm or PDF, copy and delete files and read text files.22 min
- 28Collections and dictionaries in VBAStore items by key with Collection and Scripting.Dictionary: total sales per customer, find unique values, check if a key exists and handle Mac.20 min
- 29Class modules: build your own objects in VBACreate your own objects with class modules: private fields, Property Get/Let/Set, methods, Class_Initialize, collections of objects and WithEvents.22 min
- 30Make your macros fast: speed optimization in VBASpeed up slow macros: switch off screen updating, calculation and events safely, use arrays instead of cell-by-cell loops, avoid Select and measure with Timer.20 min
- 31Control Outlook, Word and PowerPoint from Excel VBASend Outlook emails with tables and attachments, fill a Word template from Excel and understand early vs late binding, with notes on security and Mac limits.22 min
- 32VBA best practices: clean code, sharing and securityWrite VBA others can trust: naming, Option Explicit, modules, constants, code names, version control, digital signatures, add-ins and safe handling of secrets.20 min
- 33Final project: build a PDF invoice generator in VBAPut the course together: turn order lines into one numbered invoice per customer from a template, add VAT, save each as PDF and keep a log.35 min