Worksheet object
Represents a worksheet and provides the proper context for ranges, cells, and sheet-level actions.
Worksheets("Sheet1")
Set ws = ActiveWorkbook.Worksheets(1)This static page keeps the syntax and examples indexed for search, while the coding app handles interactive exploration and saved references.
What it does
Overview
Represents a worksheet and provides the proper context for ranges, cells, and sheet-level actions.
A Worksheet object anchors Excel automation to the right sheet. Using worksheet variables is one of the simplest ways to make VBA code safer and clearer because it reduces hidden reliance on ActiveSheet. It is often the first fix when a macro writes to the wrong place.
Quick reference
Syntax
Worksheets("Sheet1")
Set ws = ActiveWorkbook.Worksheets(1)
See it in practice
Examples
Qualify a report sheet
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Report")
ws.Range("A1").Value = "Ready"Qualifying actions through a worksheet variable keeps workbook context explicit.
Debug faster
Common Errors
Subscript out of range
Cause: Referencing a sheet name that does not exist in the workbook.
Fix: Validate the worksheet name or wrap the lookup with guarded error handling.
Runtime support
Compatibility
Common questions
Frequently Asked Questions
Represents a worksheet and provides the proper context for ranges, cells, and sheet-level actions.
Subscript out of range: Validate the worksheet name or wrap the lookup with guarded error handling.