Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Adding, naming Worksheets sequentially

I have workbooks with worksheets numbered sequentially 1, 2, 3 etc. -
sometimes over 100 worksheets.

I'd like to be able to add a worksheet, put it at the end, and name it last
name + 1, so if the last old worksheet was named 50, the new one will be 51.

I could not find any help in VB on this.

Thanks for any help




Sol

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Adding, naming Worksheets sequentially

Alt + F11 and insert a new module and paste this in and it will create your
sheet sequentially.

Sub addatend()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
last = ws.Name
Next ws
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = last + 1
End Sub

Mike

"Sol Apache" wrote:

I have workbooks with worksheets numbered sequentially 1, 2, 3 etc. -
sometimes over 100 worksheets.

I'd like to be able to add a worksheet, put it at the end, and name it last
name + 1, so if the last old worksheet was named 50, the new one will be 51.

I could not find any help in VB on this.

Thanks for any help




Sol


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Adding, naming Worksheets sequentially

You could try something like this also though it's not as nice as
Mikes version

Option Explicit
Dim Ws As Worksheet
Dim i, WsCnt As Integer

Private Sub CommandButton1_Click() ' Rename all existing sheets
i = 1
For Each Ws In Worksheets
Ws.Name = "test" & i
i = i + 1
Next Ws
End Sub

Private Sub CommandButton2_Click() 'Add sheet to end and name it
WsCnt = Worksheets.Count
Sheets.Add After:=Sheets("test" & WsCnt)
ActiveSheet.Name = "test" & WsCnt + 1
End Sub

S

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Adding, naming Worksheets sequentially

Try something like

With ThisWorkbook.Worksheets
.Add(after:=.Item(.Count)).Name = CInt(.Item(.Count).Name) + 1
End With


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email on the web site)

"Sol Apache" wrote in message
...
I have workbooks with worksheets numbered sequentially 1, 2, 3 etc. -
sometimes over 100 worksheets.

I'd like to be able to add a worksheet, put it at the end, and name it
last
name + 1, so if the last old worksheet was named 50, the new one will be
51.

I could not find any help in VB on this.

Thanks for any help




Sol


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Adding, naming Worksheets sequentially

Belated but many thanks for these macros - Incidental and Mike

Sorry, got involved in something else which has taken up all my time.

Mike's macro works instantly. Still figuring out Incidental's, and learning
more about Excel.

Sol


On 14/3/07 13:15, in article
, "Incidental"
wrote:

You could try something like this also though it's not as nice as
Mikes version

Option Explicit
Dim Ws As Worksheet
Dim i, WsCnt As Integer

Private Sub CommandButton1_Click() ' Rename all existing sheets
i = 1
For Each Ws In Worksheets
Ws.Name = "test" & i
i = i + 1
Next Ws
End Sub

Private Sub CommandButton2_Click() 'Add sheet to end and name it
WsCnt = Worksheets.Count
Sheets.Add After:=Sheets("test" & WsCnt)
ActiveSheet.Name = "test" & WsCnt + 1
End Sub

S


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
Adding data sequentially Dave Newman Excel Discussion (Misc queries) 1 March 28th 07 03:01 AM
Adding and naming new worksheets Byron[_5_] Excel Programming 1 September 9th 05 05:21 AM
Adding and Naming Multiple Worksheets Byron Excel Worksheet Functions 6 September 8th 05 02:52 AM
Naming and Adding Worksheets Brenda Excel Programming 2 February 3rd 05 10:37 PM
Quick question about dynamically adding and naming worksheets Robbyn Excel Programming 2 August 2nd 04 01:25 AM


All times are GMT +1. The time now is 10:00 PM.

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

About Us

"It's about Microsoft Excel"