convert list to sheet tabs (2003 SP3)

steveh
SilverLounger
Posts: 1952
Joined: 26 Jan 2010, 12:46
Location: Nr. Heathrow Airport

convert list to sheet tabs (2003 SP3)

Post by steveh »

Evening all

I have 8 existing worksheets and I would like to add another 61, emp1:emp61. I have created a list on a worksheet highlighted it and then run the following code

Code: Select all

Sub NameTabs()
Dim N As Integer
 On Error Resume Next
 For Each x In Selection
     N = N + 1
     Sheets(N).Name = x
 Next
End Sub
But all that is happening is the 8 existing tabs are renamed emp1:emp8. Any examples please of how to add the new sheets and rename them as required?
Steve
http://www.freightpro-uk.com" onclick="window.open(this.href);return false;
“Tell me and I forget, teach me and I may remember, involve me and I learn.”
― Benjamin Franklin

User avatar
HansV
Administrator
Posts: 78523
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: convert list to sheet tabs (2003 SP3)

Post by HansV »

Unlike in fantasy novels, naming something will not magically create it in Excel. Try this:

Code: Select all

Sub NameTabs()
  For Each x In Selection
    Worksheets.Add.Name = x
  Next x
End Sub
Last edited by HansV on 02 Jan 2011, 20:24, edited 1 time in total.
Reason: to correct typo (Workheets > Worksheets)
Best wishes,
Hans

steveh
SilverLounger
Posts: 1952
Joined: 26 Jan 2010, 12:46
Location: Nr. Heathrow Airport

Re: convert list to sheet tabs (2003 SP3)

Post by steveh »

HansV wrote:Unlike in fantasy novels, naming something will not magically create it in Excel. Try this:

Code: Select all

Sub NameTabs()
  For Each x In Selection
    Workheets.Add.Name = x
  Next x
End Sub
Hi Hans

I must be reading the wrong novels :grin:

Using the code I get run time error 424 - Object required? The MS help on it was as clear as mud to me I am afraid
Steve
http://www.freightpro-uk.com" onclick="window.open(this.href);return false;
“Tell me and I forget, teach me and I may remember, involve me and I learn.”
― Benjamin Franklin

User avatar
HansV
Administrator
Posts: 78523
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: convert list to sheet tabs (2003 SP3)

Post by HansV »

Sorry, a typo. Workheets should be Worksheets.
Best wishes,
Hans

steveh
SilverLounger
Posts: 1952
Joined: 26 Jan 2010, 12:46
Location: Nr. Heathrow Airport

Re: convert list to sheet tabs (2003 SP3)

Post by steveh »

HansV wrote:Sorry, a typo. Workheets should be Worksheets.
Fantastic

Thanks Hans, and it runs so quick!
Steve
http://www.freightpro-uk.com" onclick="window.open(this.href);return false;
“Tell me and I forget, teach me and I may remember, involve me and I learn.”
― Benjamin Franklin