Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Generic Sheet Names

I'm creating a spreadsheet with a macro to consolidate the data on individual
worksheets. The spreadsheet will be used as a template and copied as required
for different scenarios; the worksheets will then be renamed for specific
part numbers. Is there a way I can identify the worksheets with their
generic names (Sheet1, Sheet2, etc.) in the Visual Basic code of the macro so
they will still work even when the individual sheets are renamed?
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default Generic Sheet Names

refer to the sheets by index number eg
sheets(1)
sheets(2)
sheets(3)
the index number is the order in which they were created in the new workbook
sheets(1).name will return a name you can work with
or when you rename your sheets assign it to a variable
sheet1.name = "Yourname"
yourn = sheet1.name
sheets(yourn).range("a1").value = yourn


"ckrogers" wrote:

I'm creating a spreadsheet with a macro to consolidate the data on individual
worksheets. The spreadsheet will be used as a template and copied as required
for different scenarios; the worksheets will then be renamed for specific
part numbers. Is there a way I can identify the worksheets with their
generic names (Sheet1, Sheet2, etc.) in the Visual Basic code of the macro so
they will still work even when the individual sheets are renamed?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Generic Sheet Names

Hi,

Just to clarify - Sheets(1) will return the first sheet in a Workbook, not
the first sheet that was created in that Workbook. So if the user changes
the order of the sheets, you will get unexpected results with this method.

You can refer to the Codenames of the Worksheets, which will remain the same
even if the user (or you) changes the sheet name. The Codename is displayed
in the VBE Project window (under Microsoft Excel Objects). If you select
the sheet icon for the desired Worksheet, you can modify the (Name) property
in the Properties window. I typically use "ws" as a prefix - ie, "wsData",
"wsAssumptions", etc. Then, in your code, you can use it like you would an
object reference:

wsData.Range("A1").ClearContents
MsgBox wsAssumptions.Name

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


ckrogers wrote:
I'm creating a spreadsheet with a macro to consolidate the data on
individual worksheets. The spreadsheet will be used as a template and
copied as required for different scenarios; the worksheets will then
be renamed for specific part numbers. Is there a way I can identify
the worksheets with their generic names (Sheet1, Sheet2, etc.) in the
Visual Basic code of the macro so they will still work even when the
individual sheets are renamed?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Generic Sheet Names

Thanks so much for your help. Here's my actual code ... I'm not sure how to
incorporate the your logic?? In the code following Sheet1 = 'Part 1 Color
1'; Sheet2 = 'Part 1 Color 2'; Sheet3 = 'Part 1 Color 3'

Sub Consolidate_LH()
'
' Consolidate_LH Macro
' Macro recorded 12/18/2004 by Cindy Rogers
'

'
Range("Consolidate_1").Select
Selection.Consolidate Sources:=Array( _
"'Part 1 Color 1'!R29C1:R46C32" _
, _
"'Part 1 Color 2'!R29C1:R46C32" _
, _
"'Part 1 Color 3'!R29C1:R46C32" _
), Function:=xlSum, TopRow:=False, LeftColumn:=True,
CreateLinks:=False
ActiveWindow.SmallScroll Down:=23
Range("O61").Select
End Sub

"Jake Marx" wrote:

Hi,

Just to clarify - Sheets(1) will return the first sheet in a Workbook, not
the first sheet that was created in that Workbook. So if the user changes
the order of the sheets, you will get unexpected results with this method.

You can refer to the Codenames of the Worksheets, which will remain the same
even if the user (or you) changes the sheet name. The Codename is displayed
in the VBE Project window (under Microsoft Excel Objects). If you select
the sheet icon for the desired Worksheet, you can modify the (Name) property
in the Properties window. I typically use "ws" as a prefix - ie, "wsData",
"wsAssumptions", etc. Then, in your code, you can use it like you would an
object reference:

wsData.Range("A1").ClearContents
MsgBox wsAssumptions.Name

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


ckrogers wrote:
I'm creating a spreadsheet with a macro to consolidate the data on
individual worksheets. The spreadsheet will be used as a template and
copied as required for different scenarios; the worksheets will then
be renamed for specific part numbers. Is there a way I can identify
the worksheets with their generic names (Sheet1, Sheet2, etc.) in the
Visual Basic code of the macro so they will still work even when the
individual sheets are renamed?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Generic Sheet Names

Thanks so much for your help. Here's my actual code ... I'm not sure how to
incorporate the your logic?? In the code following Sheet1 = 'Part 1 Color
1'; Sheet2 = 'Part 1 Color 2'; Sheet3 = 'Part 1 Color 3'

Sub Consolidate_LH()
'
' Consolidate_LH Macro
' Macro recorded 12/18/2004 by Cindy Rogers
'

'
Range("Consolidate_1").Select
Selection.Consolidate Sources:=Array( _
"'Part 1 Color 1'!R29C1:R46C32" _
, _
"'Part 1 Color 2'!R29C1:R46C32" _
, _
"'Part 1 Color 3'!R29C1:R46C32" _
), Function:=xlSum, TopRow:=False, LeftColumn:=True,
CreateLinks:=False
ActiveWindow.SmallScroll Down:=23
Range("O61").Select
End Sub


"ben" wrote:

refer to the sheets by index number eg
sheets(1)
sheets(2)
sheets(3)
the index number is the order in which they were created in the new workbook
sheets(1).name will return a name you can work with
or when you rename your sheets assign it to a variable
sheet1.name = "Yourname"
yourn = sheet1.name
sheets(yourn).range("a1").value = yourn


"ckrogers" wrote:

I'm creating a spreadsheet with a macro to consolidate the data on individual
worksheets. The spreadsheet will be used as a template and copied as required
for different scenarios; the worksheets will then be renamed for specific
part numbers. Is there a way I can identify the worksheets with their
generic names (Sheet1, Sheet2, etc.) in the Visual Basic code of the macro so
they will still work even when the individual sheets are renamed?

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
using the Excel generic worksheet names instead of user-given names in code Paul Excel Discussion (Misc queries) 5 June 26th 09 08:44 PM
Generic Worksheet Names Tendresse Excel Discussion (Misc queries) 2 July 9th 08 10:33 PM
Cell names = sheet names Vince Excel Worksheet Functions 9 February 8th 08 03:59 PM
I want to print out the sheet tabs (sheet names) Sundus Excel Worksheet Functions 3 February 23rd 05 08:34 PM
return all worksheet tab names and chart sheet tab names in report - an example DataFreakFromUtah Excel Programming 2 October 6th 04 08:09 PM


All times are GMT +1. The time now is 11:07 AM.

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

About Us

"It's about Microsoft Excel"