- 01Setting up (what you'll need)
- 02Your first output (MsgBox)
- 03Variables (Dim)
- 04Branching (the If statement)
- 05Repeating (the For statement)
- 06Repeating (the Do While statement)
- 07Writing a Sub procedure
- 08Function procedures (work that returns a value)
- 09Reading and writing cells (Range and Cells)
- 10Working with arrays
- 11Working with strings
- 12The With statement
- 13Object variables and working with worksheets
- 14Looping over cells (For Each)
- 15Error handling (On Error)
- 16The Select Case statement
- 17Arguments (ByVal and ByRef)
- 18Working with collections (Collection)
- 19Recording macros and event procedures
- 20[Project] Build a small inventory sheet
The With statement
This lesson covers the With statement, which gathers several operations on the same object.
Writing With object ... .property = value ... End With lets you group several operations on the same object, leaving the object name out each time.
The sample code uses With Range("A1") to gather setting the value and setting the font to bold into one block (the actual cell formatting is not reflected in this lesson).
A common early stumble is forgetting End With. A With block must always be closed with it.
In professional work, gathering several lines that reach into the same cell or object with With makes the code easier to read and faster to run.
๐งช This site can't compile or run VBA directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
