Open worksheet based on Cell Value

Dukesford

Board Regular
Joined
May 30, 2007
Messages
106
I wrote a macro that creates a new worksheet based on the month and year and renames it based on that and it won't create a new worksheet until the first of every month nor will it create it if the worksheets name exists. For instance next month when it is ran it will create a new worksheet named "9-07".

Later on a user needs to do some updates then calculate some things, so I want it after it is running this other code to select the newly created worksheet "9-07". I have this referenced in cell A1 and it would be nice if you could activate a worksheet based on a cell reference. Does anyone know how? So cell A1 = the new worksheet "9-07".
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Steel Monkey

New Member
Joined
Jun 20, 2007
Messages
4
Assuming the new sheet name in in sheet1 in cell a1 try something like the following(changing the sheet names etc as needed) :

Code:
Option Explicit
Sub selectasheet()
Sheets("" & Sheets("Sheet1").Range("A1").Value).Select
End Sub

Let me know how it goes!
 
Upvote 0

zzjasonzz

Well-known Member
Joined
Apr 23, 2006
Messages
649
Steel,

What is the purpose of the "" & Sheets("Sheet1").Range("A1").Value

It should work fine using just Sheets(Sheets("Sheet1").Range("A1").value).Select
 
Upvote 0

Dukesford

Board Regular
Joined
May 30, 2007
Messages
106
I am running into an error "runtime time error '9': Subscript out of range." Any suggestions? Also what are you assuming Sheet1 represents? When I am looking in Microsoft Visual Basic I see that it is actually Sheet 48 as of now, but with more testing before I get it to work smoothly that will increase, and as time goes on the number of sheets will increase based on the month. Also what does the "Option Explicit" mean, where should that be? I am using modules so does that matter?
 
Upvote 0

Dukesford

Board Regular
Joined
May 30, 2007
Messages
106
Got it. I changed it a little and it no longer give me that error. Here is the code:

Code:
Sheets("" & Range("A1").Value).Select
 
Upvote 0

Forum statistics

Threads
1,190,610
Messages
5,981,916
Members
439,743
Latest member
KatieO

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
Top