PC Review


Reply
Thread Tools Rate Thread

Create Tabs from Existing Tab

 
 
Ardy
Guest
Posts: n/a
 
      30th Nov 2006
Create Tabs from Existing Tab

The Last Topic was getting too long for History See
http://groups.google.com/group/micro...786c2446bdc465

With much help from Bob, I have a VB code in which I am creating new
tabs from a list and existing tab called template. The code works fine
with one exception that at the end it wants to create another tab with
the same name Template and run to an run time error for duplication of
existing tabs and creates a one called Template(2).

-------------------------------------Existing Code
Private Sub CommandButton1_Click()
' Create tabs from the list
' Bob from microsoft.public.excel.programming 11/28/2006

Dim LastCell As Range, Rng As Range, cell As Range
Dim WS As Worksheet

Set WS = ActiveSheet
Set LastCell = WS.Cells(Rows.Count, "A").End(xlUp)
Set Rng = WS.Range("A2", LastCell)

For Each cell In Rng
If Not IsEmpty(cell) Then
Sheets("Template").Copy after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = cell.Value
End If
Next
End Sub
-----------------------------------------------------------------------------------

 
Reply With Quote
 
 
 
 
Ardy
Guest
Posts: n/a
 
      30th Nov 2006
One more thing.... With testing the code seem to work with 25 name on
list and run to the above error with the any more names i.e. 26 and up.
Ardy wrote:
> Create Tabs from Existing Tab
>
> The Last Topic was getting too long for History See
> http://groups.google.com/group/micro...786c2446bdc465
>
> With much help from Bob, I have a VB code in which I am creating new
> tabs from a list and existing tab called template. The code works fine
> with one exception that at the end it wants to create another tab with
> the same name Template and run to an run time error for duplication of
> existing tabs and creates a one called Template(2).
>
> -------------------------------------Existing Code
> Private Sub CommandButton1_Click()
> ' Create tabs from the list
> ' Bob from microsoft.public.excel.programming 11/28/2006
>
> Dim LastCell As Range, Rng As Range, cell As Range
> Dim WS As Worksheet
>
> Set WS = ActiveSheet
> Set LastCell = WS.Cells(Rows.Count, "A").End(xlUp)
> Set Rng = WS.Range("A2", LastCell)
>
> For Each cell In Rng
> If Not IsEmpty(cell) Then
> Sheets("Template").Copy after:=Worksheets(Worksheets.Count)
> ActiveSheet.Name = cell.Value
> End If
> Next
> End Sub
> -----------------------------------------------------------------------------------


 
Reply With Quote
 
Ardy
Guest
Posts: n/a
 
      30th Nov 2006
You are right........There was one of the name that was repeating.
Thanks
John Bundy wrote:
> The reason it is stopping is because in your list, one of the words you are
> using to name a sheet with in the name of an already existing sheet. If i'm
> not mistaken the max length of a sheet name is 31 characters including spaces
> and symbols.
>
> -John
>
> "Ardy" wrote:
>
> > One more thing.... With testing the code seem to work with 25 name on
> > list and run to the above error with the any more names i.e. 26 and up.
> > Ardy wrote:
> > > Create Tabs from Existing Tab
> > >
> > > The Last Topic was getting too long for History See
> > > http://groups.google.com/group/micro...786c2446bdc465
> > >
> > > With much help from Bob, I have a VB code in which I am creating new
> > > tabs from a list and existing tab called template. The code works fine
> > > with one exception that at the end it wants to create another tab with
> > > the same name Template and run to an run time error for duplication of
> > > existing tabs and creates a one called Template(2).
> > >
> > > -------------------------------------Existing Code
> > > Private Sub CommandButton1_Click()
> > > ' Create tabs from the list
> > > ' Bob from microsoft.public.excel.programming 11/28/2006
> > >
> > > Dim LastCell As Range, Rng As Range, cell As Range
> > > Dim WS As Worksheet
> > >
> > > Set WS = ActiveSheet
> > > Set LastCell = WS.Cells(Rows.Count, "A").End(xlUp)
> > > Set Rng = WS.Range("A2", LastCell)
> > >
> > > For Each cell In Rng
> > > If Not IsEmpty(cell) Then
> > > Sheets("Template").Copy after:=Worksheets(Worksheets.Count)
> > > ActiveSheet.Name = cell.Value
> > > End If
> > > Next
> > > End Sub
> > > -----------------------------------------------------------------------------------

> >
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How do I sort tabs on an existing spreadsheet? Jim Cone Microsoft Excel Worksheet Functions 1 19th Dec 2006 02:06 AM
Rename all existing worksheet tabs =?Utf-8?B?TWlrZU0=?= Microsoft Excel Misc 14 20th Oct 2006 03:29 AM
Rename existing tabs =?Utf-8?B?RGF3biBSaG9hZHM=?= Microsoft Excel Programming 8 27th May 2005 10:00 PM
Re: Adding Tabs to Existing Form PC Datasheet Microsoft Access Getting Started 1 23rd Aug 2003 01:00 AM
Re: Adding Tabs to Existing Form Ken Snell Microsoft Access Getting Started 0 22nd Aug 2003 11:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:31 PM.