Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default renaming sheets

I want to use VBA to rename 8 sheets in a workbook with
the names of employees stored in a range in one worksheet.
I can do this by refering to the existing name of the
sheet but how can i refer to the sheets in order using
code.

i.e if sheet 1 is named PTurner, I can rename it by
refering to Sheets ("P Turner"), but if this name has been
changed to something else then an error occurs. I need the
code to recognise it as 'sheet1' whatever the name entered
currently may be. Can you tell how I can do this please.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default renaming sheets

You use the index to refer to the sheets in order.

For example, If you have 3 sheets - Mike, John and George -
then Sheets(1) is the same as saying Sheets("Mike"),
Sheets(2) is the same as Sheets("John"), and so on... The
index is 1-based, meaning that 1 is the first and 2 is the
second...

The only issue with doing it this way is that if the
user "accidentally" moves the order, then the indexes will
change. To get that to work, you could use the .Name
property. For example:

For x = 1 to Sheets.Count
If Sheets(1).Name = "Mike" Then
<do something
Exit For
end if
Next x

Just some ideas to get your gears workin'!

-----Original Message-----
I want to use VBA to rename 8 sheets in a workbook with
the names of employees stored in a range in one

worksheet.
I can do this by refering to the existing name of the
sheet but how can i refer to the sheets in order using
code.

i.e if sheet 1 is named PTurner, I can rename it by
refering to Sheets ("P Turner"), but if this name has

been
changed to something else then an error occurs. I need

the
code to recognise it as 'sheet1' whatever the name

entered
currently may be. Can you tell how I can do this please.
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default renaming sheets

This code will copy "P Tuner" 8 times then rename it to what ehatever you
want.
This is if "P Tumer" is sheet(1).

Private Sub CommandButton1_Click()

For y = 1 To 8
Sheets("P Turner").Select
Sheets("P Turner").Copy After:=Sheets(1)
Sheets("P Turner (2)").Name = "Employee " & y
Next y

End Sub


"Jeremy" wrote in message
...
I want to use VBA to rename 8 sheets in a workbook with
the names of employees stored in a range in one worksheet.
I can do this by refering to the existing name of the
sheet but how can i refer to the sheets in order using
code.

i.e if sheet 1 is named PTurner, I can rename it by
refering to Sheets ("P Turner"), but if this name has been
changed to something else then an error occurs. I need the
code to recognise it as 'sheet1' whatever the name entered
currently may be. Can you tell how I can do this please.



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
Renaming Chart Sheets in 2007 Ailish Charts and Charting in Excel 0 July 22nd 09 02:03 PM
Renaming Sheets Accor Excel Discussion (Misc queries) 6 August 15th 08 04:43 PM
Renaming sheets with part of original name MichaelR Excel Worksheet Functions 1 June 5th 08 05:30 AM
renaming all work-sheets at once Narendra Boga[_2_] Excel Discussion (Misc queries) 4 June 6th 07 03:24 AM
Renaming multiple sheets Mark T Excel Worksheet Functions 14 July 16th 05 02:22 AM


All times are GMT +1. The time now is 02:12 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"