Reference Ever Changing Sheet Name

Majawat

New Member
Joined
Jun 14, 2011
Messages
49
I have one sheet that constantly changes names. One minute it may be called "Steigl Goldbrau" and the next "Blue Moon".

I would like to be able to reference it with the Sheet() function but not sure how as the name inside would change...

Maybe keep a variable in the VBA with the name of the sheet and update it as necessary? Anyone know of a better way?

Thanks for any and all suggestions!
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
You should use the CodeName for this instead. Or you could add a hidden name to the worksheet and look for it when trying to get a reference to the worksheet.
 
Upvote 0
Each Sheet has 3 ways to identify itself.

1) User Name - What's displayed on the Sheet Tab (too easily Changable)
2) Sheet Index Number -- such as in the immediate window typing ? activesheet.index
3) CodeName - Permanent (Hidden/Official) name - in the VBE - the sheets properties window 1st position, named in left column (Name) << In ()'s -- Change the default name in the right-hand column to our choice, like MySheet.

Then refer to it in code simply as --- mysheet.activate
 
Upvote 0
how does it get changed?

I haven't figured out exactly how I'm going to do that actually... Thanks for pointing that out for me!

You should use the CodeName for this instead. Or you could add a hidden name to the worksheet and look for it when trying to get a reference to the worksheet.

How do I use the CodeName then? Like this, for example?

Code:
ThisWorkbook.VBProject.VBComponents("Sheet3").Activate


<HR>

What I'm trying to do here is have a cell on "BeerList" with a hyperlink. When that hyperlink is clicked, it opens an browser page, switches the ActiveSheet to the name changing sheet, then change the name of the now ActiveSheet to the value in the original cell.
 
Upvote 0
Ok! I got it. Thanks you Juan Pablo González for getting me started!

Instead of referencing the sheet with Sheets("Sheet1"), changing the name of a sheet via the CodeName and then activating the sheet goes like this:

Code:
Sheet1.Name = NAME
Sheet1.Activate

This way, no matter what the name is, using the Sheet1 will work. When using CodeNames you don't use the Sheets() function, just the code name.


For anyone curious, I got help via this website: http://www.ozgrid.com/VBA/excel-vba-sheet-names.htm
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,726
Members
452,939
Latest member
WCrawford

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