Excel VBA Activate Sheet: Syntax, Examples, and Fixes

VBA & macros · Updated November 2, 2026

Excel VBA Activate Sheet: Syntax, Examples, and Fixes

To activate a worksheet with VBA, reference it by name and call its Activate method: ThisWorkbook.Worksheets("Summary").Activate. The sheet must be visible, and the workbook containing it must be open; use a workbook-qualified reference so the macro does not accidentally target a sheet in another file.

What activating a sheet means

Activation makes a sheet the current sheet shown in Excel. After activation, that worksheet is normally the one a person sees and the one referred to by ActiveSheet. This is useful when a macro needs to take the user to a report, display an input form stored on a worksheet, or leave a workbook at a particular page when a task finishes.

Activation is a change to Excel’s user interface, not a requirement for every VBA operation. A macro can read or write a worksheet by referring to its object directly, even while another sheet is visible. That distinction matters in larger macros: avoiding unnecessary sheet changes can make code easier to follow and can prevent the screen from jumping around.

In Excel VBA, Worksheets refers to worksheet tabs, while Sheets can include worksheets and chart sheets. Choose the collection that matches what you intend to activate. For an ordinary grid of cells, use Worksheets.

Basic syntax and a safe example

The general pattern is workbook.Worksheets("SheetName").Activate. Replace SheetName with the worksheet’s tab name. In code stored in the workbook that contains the target sheet, ThisWorkbook is a clear way to identify that file.

Before running a macro, save a copy of the workbook: VBA macros cannot be undone with Ctrl+Z. The following example also activates the workbook explicitly, which makes the intended destination clear if another workbook is currently in front.

Sub ActivateSummary()
    Dim wb As Workbook
    Dim ws As Worksheet

    ' Use the workbook that contains this macro.
    Set wb = ThisWorkbook
    Set ws = wb.Worksheets("Summary")

    ' Bring the workbook and its worksheet to the front.
    wb.Activate
    ws.Activate
End Sub

In the Visual Basic Editor, put this procedure in a standard module, such as one created with Insert > Module. In Excel for Microsoft 365 on Windows, Alt+F11 opens or returns to the Visual Basic Editor. On many Mac keyboards, Option+F11 opens it; some require Fn+Option+F11. Keyboard behavior can vary with the Mac’s function-key settings.

Activate a sheet by name or position

A sheet name is usually the most readable choice. It also remains meaningful if someone changes the order of the worksheet tabs. The name in the reference must correspond to the tab name, not the VBA code name shown in the Properties window. For example, a sheet may have a code name such as Sheet2 but a visible tab name of Summary.

You can also refer to a worksheet by its position in the Worksheets collection. The index starts at 1 and follows the current tab order, so inserting or moving a sheet can change what a number refers to. Save a copy before running this macro as well; it cannot be reversed with Ctrl+Z.

Sub ActivateFirstWorksheet()
    Dim wb As Workbook
    Dim ws As Worksheet

    ' The first worksheet means the first item in Worksheets order.
    Set wb = ThisWorkbook
    Set ws = wb.Worksheets(1)

    wb.Activate
    ws.Activate
End Sub

Use a numeric index for a deliberate positional task, not as a substitute for a stable name. For instance, Worksheets(1) means the first worksheet, whereas Sheets(1) could refer to a chart sheet if one appears first. That difference can lead to an unexpected object or an error when later code assumes it has a grid of cells.

Choose the correct workbook reference

Workbook qualification prevents a common source of mistakes: acting on whichever file happens to be active. ThisWorkbook means the workbook in which the running VBA code is stored. ActiveWorkbook means the workbook currently active in Excel, which may be a different file—for example, if an add-in or personal macro workbook contains the code.

If the intended workbook is open but is not the one containing the macro, you can refer to it by its open workbook name. The name must match the workbook’s name in Excel, including its file extension when applicable. This example assumes a workbook named Budget.xlsx is already open. Save a copy before running any macro; Ctrl+Z will not undo it.

Sub ActivateBudgetSheet()
    Dim wb As Workbook
    Dim ws As Worksheet

    ' This workbook must already be open in Excel.
    Set wb = Workbooks("Budget.xlsx")
    Set ws = wb.Worksheets("Overview")

    wb.Activate
    ws.Activate
End Sub

If the workbook is not open, a reference through Workbooks("Budget.xlsx") cannot find it. Opening a file is a separate action that should be handled deliberately, especially when the file path, security, or whether changes should be saved matters. Avoid relying on ActiveWorkbook when the macro may be launched from more than one workbook.

Activate versus Select

Activate makes an object current; Select selects it. For a single worksheet, either call may appear to have the same visible result. The distinction becomes important when multiple worksheets are selected together, which Excel calls a grouped selection. One selected sheet is active, but other sheets can also be selected.

Grouped sheets can be useful when entering the same value or applying the same formatting to corresponding cells across several worksheets. They can also be risky: an edit may affect every selected sheet. Calling Activate is not a general-purpose way to ungroup worksheets. If you need to ensure that only one worksheet is selected, use Select with the appropriate argument, or select a different single sheet as part of the intended action.

For ordinary navigation, Activate expresses the intent directly. For editing data, it is often better to work with a worksheet variable and address its cells, rather than selecting a sheet and then using Selection. This keeps the target explicit and reduces dependence on what the user last clicked.

Common errors and how to fix them

A failed activation usually comes down to the target reference or the sheet’s visibility. Check the workbook and sheet names first, then verify that the target can be displayed. Common causes include:

  • Subscript out of range: Excel could not find the named workbook or sheet in the collection you referenced. Check spelling, the actual tab name, the workbook’s open state, and whether you used ThisWorkbook when you meant another file.
  • Sheet is hidden: A hidden worksheet cannot be activated. It must first be made visible. A worksheet set to xlSheetVeryHidden is also unavailable for activation until its visibility is changed through VBA or the Visual Basic Editor.
  • Wrong workbook is active: An unqualified reference such as Sheets("Summary").Activate can resolve against the active workbook. Qualify it with ThisWorkbook or a workbook variable.
  • Wrong collection: If the target is a chart sheet, it is not a member of Worksheets. Use Sheets when chart sheets are intentionally included, and check the object type before using worksheet-specific properties.

Do not make a hidden sheet visible automatically unless that is appropriate for the workbook’s design. Hidden sheets may contain implementation details or data users are not meant to edit. If a macro is supposed to reveal one, make that step explicit and consider restoring its original visibility afterward.

When activation is unnecessary

A macro that only reads or changes cells does not normally need to activate the worksheet. This example writes a heading to cell A1 on the Summary worksheet without changing the sheet shown in Excel. Save a copy before running it because macros cannot be undone with Ctrl+Z.

Sub WriteSummaryHeading()
    Dim ws As Worksheet

    ' Address the target directly; no activation is needed.
    Set ws = ThisWorkbook.Worksheets("Summary")
    ws.Range("A1").Value = "Monthly summary"
End Sub

Direct references are particularly helpful when a macro processes several sheets, runs in the background, or needs to avoid disrupting the user’s current view. Activation is still appropriate when navigation is part of the requested result—for example, when a report-building macro should finish by displaying the completed report.

Events, security, and platform notes

Activating a worksheet can run its Worksheet_Activate event procedure, if one exists. That event can update displays or run other code. Be cautious if an activation event activates another sheet in turn: chained event code can cause confusing navigation or repeated execution. Keep event procedures focused, and test workbook behavior with a saved copy.

VBA macros run in the desktop versions of Excel, not in Excel for the web. Excel for the web can open a macro-enabled workbook, but it does not run VBA macros. Excel for Mac supports VBA, though code that depends on Windows-only components, file paths, or system features may need changes. The basic worksheet activation examples here use standard Excel objects.

Only run macros from sources you trust. Excel’s macro security settings may block code or ask whether to enable it; do not enable unknown macros just to activate a sheet. The direct VBA method is also different from a manual worksheet-tab click: clicking a tab changes the view without running a macro, and may be the simplest option for a one-time move.

Frequently Asked Questions

How do I activate a worksheet by its tab name?
Use ThisWorkbook.Worksheets("SheetName").Activate, replacing SheetName with the tab name. Qualify the workbook when the target may not be in the workbook currently active.

Why does VBA say “Subscript out of range” when I activate a sheet?
The referenced workbook or sheet was not found in that collection. Confirm the exact tab name, that the workbook is open, and whether the code should use ThisWorkbook or another workbook reference.

Can VBA activate a hidden worksheet?
No. A worksheet must be visible to activate it. Change its visibility deliberately before activation if that is suitable, and remember that a very hidden sheet must be revealed through VBA or the Visual Basic Editor.

What is the difference between ActiveSheet and a worksheet variable?
ActiveSheet refers to the sheet currently active in the interface. A worksheet variable refers to the specific worksheet assigned to it, even when another sheet is active. Explicit variables are generally safer for code that edits data.

Does activating a worksheet work in Excel for the web?
Excel for the web does not run VBA macros. Use desktop Excel to run the macro, or click the worksheet tab in the web app for manual navigation.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.