logo
search
VBA & Macro Problems

How to Select a Worksheet by Name Using Excel VBA Macro

Maira MehtabMaira Mehtab Sep 27, 2026 870 views

Question details

The user wants to create a macro that navigates to a specific worksheet dynamically, using a sheet name stored in a designated cell.

Product
Microsoft Excel
Device & OS
not provided
Scenario
Creating a dynamic navigation button that changes its target worksheet when a cell's value is updated.
Observed behavior
A VBA script is needed to read the worksheet name from a cell (e.g., B1) and select that corresponding sheet automatically.
Before you start

Ensure that you have enabled the Developer tab in your spreadsheet settings and saved your file as a Macro-Enabled Workbook (.xlsm) to allow VBA code to run properly.

Solution 1Recommended

Use VBA Code to Select a Worksheet Based on Cell Value

Write a simple VBA script that reads the target sheet name from a specific cell and jumps to it via a Form Control button.

This method uses a small VBA script combined with a Form Control button to create dynamic navigation. When you change the text in the reference cell, the button automatically links to the updated sheet name.

1
Open the VBA Editor

Press ALT + F11 on your keyboard to open the VBA Editor, then click 'Insert' > 'Module' to create a new code module.

2
Enter the VBA Code

Copy and paste the following code into the module window: Sub Jump2Sheet() On Error Resume Next Worksheets(Range("B1").Value).Select End Sub

3
Insert a Form Control Button

Return to your spreadsheet, go to the Developer tab, click 'Insert', and select 'Button (Form Control)'. Draw the button on your sheet.

4
Assign the Macro

When the 'Assign Macro' dialog appears, select 'Jump2Sheet' from the list and click 'OK'. Test it by typing an existing sheet name into cell B1 and clicking your new button.

Exact Match Required: Make sure the cell value exactly matches an existing worksheet name. The macro uses 'On Error Resume Next', meaning if the sheet does not exist, nothing will happen and no error message will be shown.
Advanced Macros in WPS Office

Easily Manage VBA Macros in WPS Office Spreadsheets

WPS Office Spreadsheets provides excellent support for VBA macros, allowing you to run and edit Excel scripts seamlessly. You can automate tasks and create dynamic worksheet navigation buttons just like in Microsoft Excel.

  1. 1. Open your macro-enabled file: Launch WPS Spreadsheets and open your existing .xlsm workbook.
  2. 2. Access the VBA Editor: Navigate to the Tools tab and click on the 'Macro' or 'VBA Editor' button to write your navigation code.
  3. 3. Assign and Execute: Insert a shape or form control button, right-click it, assign your dynamic worksheet selection macro, and test the navigation.
Fully compatible with Microsoft Excel (.xlsm) macro-enabled file formats.Built-in VBA editor for writing and debugging custom macros smoothly.Lightweight architecture that runs seamlessly even on older devices.Free and easy-to-use interface with familiar ribbon menus for easy migration.
microsoft office alternative - wps office

Frequently Asked Questions

Why is my VBA macro not navigating to the specified worksheet?

This usually happens if the text in your reference cell does not exactly match the actual sheet name (including spaces), or if macros are disabled in your workbook's security settings.

Can I use a cell from a different worksheet as the reference?

Yes. You can modify the code to reference a specific sheet, such as Worksheets(Sheets("Menu").Range("B1").Value).Select, so the macro always checks the 'Menu' sheet for the target name regardless of which sheet is currently active.

How do I add a Form Control button if the Developer tab is missing?

You first need to enable the Developer tab. Go to File > Options > Customize Ribbon, and check the box next to 'Developer' in the right pane. Once enabled, you can find the Insert Button option on the Developer tab.