Activate sheet based on cell value

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,602
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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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,215,227
Messages
6,123,745
Members
449,116
Latest member
alexlomt

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