PC Review


Reply
Thread Tools Rate Thread

Adding, naming Worksheets sequentially

 
 
Sol Apache
Guest
Posts: n/a
 
      14th Mar 2007
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      14th Mar 2007
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
>
>

 
Reply With Quote
 
Incidental
Guest
Posts: n/a
 
      14th Mar 2007
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 With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      14th Mar 2007
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" <(E-Mail Removed)> wrote in message
news:C21D9E49.3F7A%(E-Mail Removed)...
>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
>


 
Reply With Quote
 
Sol Apache
Guest
Posts: n/a
 
      30th Mar 2007
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
(E-Mail Removed), "Incidental"
<(E-Mail Removed)> 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 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
Adding and naming new worksheets =?Utf-8?B?Qnlyb24=?= Microsoft Excel Programming 1 9th Sep 2005 05:21 AM
Adding and Naming Multiple Worksheets =?Utf-8?B?Qnlyb24=?= Microsoft Excel Worksheet Functions 6 8th Sep 2005 02:52 AM
Naming and Adding Worksheets =?Utf-8?B?QnJlbmRh?= Microsoft Excel Programming 2 3rd Feb 2005 10:37 PM
Quick question about dynamically adding and naming worksheets =?Utf-8?B?Um9iYnlu?= Microsoft Excel Programming 2 2nd Aug 2004 01:25 AM
Adding & Naming Worksheets in a macro John Microsoft Excel Misc 3 5th Mar 2004 05:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:52 AM.