Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Unchanging Cell Color | Excel Discussion (Misc queries) | |||
Unchanging cell question | Excel Discussion (Misc queries) | |||
Cell Value & unchanging Date With Macro run | Excel Programming | |||
I want in one worksheet to relatively link to/reference cells in another without changing the format of the current worksheet. | Excel Discussion (Misc queries) | |||
Reference to ActiveX control on worksheet requires full worksheet name | Excel Programming |