With statement
Groups repeated access to the same object so code is shorter and clearer.
With object
.Property = value
End WithThis static page keeps the syntax and examples indexed for search, while the coding app handles interactive exploration and saved references.
What it does
Overview
Groups repeated access to the same object so code is shorter and clearer.
With is especially useful in Excel VBA because many macros repeatedly touch the same range, worksheet, or workbook object. It reduces repetitive object qualifiers and makes formatting or report-building blocks easier to read. It is best when one target object stays stable across several lines.
Quick reference
Syntax
With object
.Property = value
End With
See it in practice
Examples
Format a report header block
With Worksheets("Report").Range("A1:C1")
.Value = Array("Region", "Sales", "Margin")
.Font.Bold = True
.Interior.Color = RGB(217, 225, 242)
End WithWith keeps repeated Range qualifiers out of the way while formatting a block.
Debug faster
Common Errors
LogicError
Cause: Assuming the dot-prefixed members refer to a different object after leaving the With block.
Fix: Keep object-specific operations inside the With block and avoid nested ambiguity.
Runtime support
Compatibility
Common questions
Frequently Asked Questions
Groups repeated access to the same object so code is shorter and clearer.
LogicError: Keep object-specific operations inside the With block and avoid nested ambiguity.