PC Review


Reply
Thread Tools Rate Thread

Create new worksheet and use a number as its name..

 
 
Billy
Guest
Posts: n/a
 
      8th Oct 2010
I have a workbook that uses the following macro to create new
worksheets. What i would like to be able do is to create the sheet,
and have it automatically named [ in this case the name would a
number [2 or 3 or 4 or 5 etc etc]. The last sheet in the workbook
[ the rightmost tab] would be sheet '1' at the start. The newly
created sheet would be to the right if this, and I would want it to be
sheet '2'. Then the next sheet, created to the right of sheet '2',
would be named '3', and so on. How do I modify or change this VBA to
accomplish this?

Thanks,

Tonso

Dim sName As String
Dim wks As Worksheet
Answer = MsgBox("Do you want create a new MOST Sub-Operation?",
vbYesNo)
If Answer <> vbYes Then Exit Sub
Worksheets("T").Copy After:=Sheets(Worksheets.Count)
Set wks = ActiveSheet
Do While sName <> wks.Name
sName = Application.InputBox _
(Prompt:="Enter new worksheet name")
On Error Resume Next
wks.Name = sName
On Error GoTo 0
Loop
Set wks = Nothing
 
Reply With Quote
 
 
 
 
Don Guillett Excel MVP
Guest
Posts: n/a
 
      8th Oct 2010
On Oct 8, 10:11*am, Billy <wthoma...@hotmail.com> wrote:
> I have a workbook that uses the following macro to create new
> worksheets. What i would like to *be able do is to create the sheet,
> and have it automatically named [ in this case the name would *a
> number [2 or 3 or 4 or 5 etc etc]. The last sheet in the workbook
> [ the rightmost tab] would be sheet '1' at the start. The newly
> created sheet would be to the right if this, and I would want it to be
> sheet '2'. Then the next sheet, created to the right of sheet '2',
> would be named '3', and so on. How do I modify or change this VBA to
> accomplish this?
>
> Thanks,
>
> Tonso
>
> Dim sName As String
> * * Dim wks As Worksheet
> * * Answer = MsgBox("Do you want create a new MOST Sub-Operation?",
> vbYesNo)
> * * If Answer <> vbYes Then Exit Sub
> * * Worksheets("T").Copy After:=Sheets(Worksheets.Count)
> * * Set wks = ActiveSheet
> * * Do While sName <> wks.Name
> * * * * sName = Application.InputBox _
> * * * * * (Prompt:="Enter new worksheet name")
> * * * * On Error Resume Next
> * * * * wks.Name = sName
> * * * * On Error GoTo 0
> * * Loop
> * * Set wks = Nothing


Sub copysheetandnamenextindex()
Sheets("Sheet5").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = "Sh" & Sheets(Sheets.Count).Index
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
Create new workbook and new worksheet and close. Worksheet not saved Patrick Microsoft Excel Programming 1 25th Jul 2009 07:00 PM
Create new workbook and new worksheet and close. Worksheet not sav Patrick Djo Microsoft Excel Programming 0 21st Jul 2009 02:19 PM
Create new workbook and new worksheet and close. Worksheet not sav Patrick Djo Microsoft Excel Worksheet Functions 0 20th Jul 2009 07:10 PM
Enter number on a worksheet to copy row from another worksheet =?Utf-8?B?MVNH?= Microsoft Excel Worksheet Functions 1 22nd May 2007 12:15 AM
Basic Question - How do I return the worksheet number of the active worksheet? Regnab Microsoft Excel Programming 2 17th May 2006 03:02 AM


Features
 

Advertising
 

Newsgroups
 


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