Ad space (banner)
Lesson 12 / 20

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.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "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).

Ad space (banner)
Ad space (in-article)