Activate sheet based on cell value

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,604
Office Version
  1. 365
Platform
  1. Windows
Hi all

I'm using this line of code to activate a workbook sheet
Code:
Worksheets(Worksheets("Front").Range("A1").Value).Activate

So the 'value' found in cell ref A1 of the Front sheet will always be a number between 1 and 31
The workbook contains 31 sheets, named 1,2,3,4,5, etc etc thru to 31

I want the code above to activate the sheet name with the same value found in A1

For example if A1 holds the number 6 , I would like the sheet that is also called '6' to be activated, NOT SHEET6, as sheet6 may actually be called '16'

hope this makes sense and appreciate any help

Kind regards
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hia
Change .value to .text
Code:
Worksheets(Worksheets("Front").Range("A1").Text).Activate
 
Upvote 0
The value in A1 is being read as a number and VBA assumes that's a sheet index rather than a sheet name. You can either change Value to Text (as suggested in post #2 ) or you can coerce the value to text like this:

Rich (BB code):
Sheets(CStr(Sheets("Front").Range("A1").Value)).Activate
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top