Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default unchanging worksheet reference

Is there a way to refer to a worksheet other than by index or name?
Something that won't change as long as the worksheet exists.

Worksheets(1) or Worksheets("some sheet name") will no longer be valid if
someone inserts another worksheet before this one, or changes this one's
name. I'd like to be able to refer to a particular worksheet even if its
name or position in the workbook changes.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default unchanging worksheet reference

Paul

Each worksheet has a codename that does not change.

You can see these codenames in the VBE.

Expand your workbook/project and you will see a list of sheets.

Sheet1(sheetname)

Sheet1 is the codename.

To get a list of these run this macro.

Sub CreateListOfSheetsOnFirstSheet()
Dim WS As Worksheet
For i = 1 To Worksheets.Count
With Worksheets(1)
Set WS = Worksheets(i)
.Cells(i, 1).Value = WS.Name
.Cells(i, 2).Value = WS.CodeName
End With
Next i
End Sub


Gord Dibben MS Excel MVP

On Wed, 14 Mar 2007 11:38:59 -0700, "Paul Pedersen" wrote:

Is there a way to refer to a worksheet other than by index or name?
Something that won't change as long as the worksheet exists.

Worksheets(1) or Worksheets("some sheet name") will no longer be valid if
someone inserts another worksheet before this one, or changes this one's
name. I'd like to be able to refer to a particular worksheet even if its
name or position in the workbook changes.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default unchanging worksheet reference

That's perfect. Thanks!

"Gord Dibben" <gorddibbATshawDOTca wrote in message
...
Paul

Each worksheet has a codename that does not change.

You can see these codenames in the VBE.

Expand your workbook/project and you will see a list of sheets.

Sheet1(sheetname)

Sheet1 is the codename.

To get a list of these run this macro.

Sub CreateListOfSheetsOnFirstSheet()
Dim WS As Worksheet
For i = 1 To Worksheets.Count
With Worksheets(1)
Set WS = Worksheets(i)
.Cells(i, 1).Value = WS.Name
.Cells(i, 2).Value = WS.CodeName
End With
Next i
End Sub


Gord Dibben MS Excel MVP

On Wed, 14 Mar 2007 11:38:59 -0700, "Paul Pedersen"
wrote:

Is there a way to refer to a worksheet other than by index or name?
Something that won't change as long as the worksheet exists.

Worksheets(1) or Worksheets("some sheet name") will no longer be valid if
someone inserts another worksheet before this one, or changes this one's
name. I'd like to be able to refer to a particular worksheet even if its
name or position in the workbook changes.





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unchanging Cell Color Lavanya Pandian Excel Discussion (Misc queries) 2 November 6th 09 03:46 PM
Unchanging cell question DR Excel Discussion (Misc queries) 4 May 11th 07 11:43 PM
Cell Value & unchanging Date With Macro run Desert Piranha[_36_] Excel Programming 4 January 23rd 06 06:17 AM
I want in one worksheet to relatively link to/reference cells in another without changing the format of the current worksheet. [email protected] Excel Discussion (Misc queries) 0 September 22nd 05 04:39 PM
Reference to ActiveX control on worksheet requires full worksheet name Ian Ripsher[_5_] Excel Programming 3 June 25th 05 04:22 PM


All times are GMT +1. The time now is 10:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"