Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Button to copy sheet, rename sheet sequencially.


I have a Setup sheet, which has a button to creat a new sheet, which
actually copies a tamplet. When i click this button it calls the new
tab "Tamplet (2)"
Is there a sub i can put in the copy routine to auto-rename the tabs
sequencially?
Note number of tabs is based upon how many times the user clicks the
new page button.

Thanks!
~Josh


--
foxgguy2005
------------------------------------------------------------------------
foxgguy2005's Profile: http://www.excelforum.com/member.php...o&userid=23663
View this thread: http://www.excelforum.com/showthread...hreadid=378885

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Button to copy sheet, rename sheet sequencially.

Option Explicit

Public Sub AddSheets()
Dim ws As Worksheet
Set ws = Worksheets("template")
ws.Copy Worksheets(1)
SetSheetName Worksheets(1)
End Sub
Private Sub SetSheetName(ws As Worksheet)
On Error Resume Next
Dim sname As String
Dim index As Long
index = 0
Do
Err.Clear
index = index + 1
sname = "template" & Format$(index, "000")
ws.Name = sname
Loop While Err.Number < 0
End Sub

"foxgguy2005" wrote:


I have a Setup sheet, which has a button to creat a new sheet, which
actually copies a tamplet. When i click this button it calls the new
tab "Tamplet (2)"
Is there a sub i can put in the copy routine to auto-rename the tabs
sequencially?
Note number of tabs is based upon how many times the user clicks the
new page button.

Thanks!
~Josh


--
foxgguy2005
------------------------------------------------------------------------
foxgguy2005's Profile: http://www.excelforum.com/member.php...o&userid=23663
View this thread: http://www.excelforum.com/showthread...hreadid=378885


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Button to copy sheet, rename sheet sequencially.


I tried putting this into my command button as follows:
but it does not work, i'm not quite sure what i'm doing wrong here?
Thanks!

Code
-------------------
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Set ws = Worksheets("Tamplet")
ws.Copy Worksheets(1)
SetSheetName Worksheets(1)
End Sub
Private Sub SetSheetName(ws As Worksheet)
On Error Resume Next
Dim sname As String
Dim index As Long
index = 0
Do
Err.Clear
index = index + 1
sname = "Tamplet" & Format$(index, "000")
ws.Name = sname
Loop While Err.Number < 0

End Su
-------------------

--
foxgguy200
-----------------------------------------------------------------------
foxgguy2005's Profile: http://www.excelforum.com/member.php...fo&userid=2366
View this thread: http://www.excelforum.com/showthread.php?threadid=37888

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Button to copy sheet, rename sheet sequencially.


anyone help me out on this one, much appreaciate it

--
foxgguy200
-----------------------------------------------------------------------
foxgguy2005's Profile: http://www.excelforum.com/member.php...fo&userid=2366
View this thread: http://www.excelforum.com/showthread.php?threadid=37888

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Button to copy sheet, rename sheet sequencially.

I put a commmandbutton on a worksheet, double clicked on that commandbutton and
pasted your code.

It worked right out of the box.

If you're using xl97, try changing the commandbutton's .takefocusonclick
property to false.

If that's not it, what happened when you tried it?

foxgguy2005 wrote:

I tried putting this into my command button as follows:
but it does not work, i'm not quite sure what i'm doing wrong here?
Thanks!

Code:
--------------------
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Set ws = Worksheets("Tamplet")
ws.Copy Worksheets(1)
SetSheetName Worksheets(1)
End Sub
Private Sub SetSheetName(ws As Worksheet)
On Error Resume Next
Dim sname As String
Dim index As Long
index = 0
Do
Err.Clear
index = index + 1
sname = "Tamplet" & Format$(index, "000")
ws.Name = sname
Loop While Err.Number < 0

End Sub
--------------------

--
foxgguy2005
------------------------------------------------------------------------
foxgguy2005's Profile: http://www.excelforum.com/member.php...o&userid=23663
View this thread: http://www.excelforum.com/showthread...hreadid=378885


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Button to copy sheet, rename sheet sequencially.


yeah you know it works for mee to actually, i'm retarded, lol.

Thanks man, tweaked the code for only 2 index numbers and to no
include the tamplet... works like a charm, you are the MAN

--
foxgguy200
-----------------------------------------------------------------------
foxgguy2005's Profile: http://www.excelforum.com/member.php...fo&userid=2366
View this thread: http://www.excelforum.com/showthread.php?threadid=37888

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Button to copy sheet, rename sheet sequencially.

I'd say Patrick was the man!

foxgguy2005 wrote:

yeah you know it works for mee to actually, i'm retarded, lol.

Thanks man, tweaked the code for only 2 index numbers and to not
include the tamplet... works like a charm, you are the MAN!

--
foxgguy2005
------------------------------------------------------------------------
foxgguy2005's Profile: http://www.excelforum.com/member.php...o&userid=23663
View this thread: http://www.excelforum.com/showthread...hreadid=378885


--

Dave Peterson
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
Copy worksheet and rename sheet Ernst - EXE Graphics Excel Discussion (Misc queries) 4 July 25th 08 01:18 PM
Macro REQ: Automatically copy a template sheet and rename MCSmarties Excel Worksheet Functions 5 October 11th 07 09:18 PM
Copy/Rename a sheet DK Links and Linking in Excel 1 March 20th 06 05:36 AM
Copy a sheet and rename it quartz[_2_] Excel Programming 4 March 24th 05 09:36 PM
copy Sheet and rename it! John Smith[_9_] Excel Programming 3 September 7th 04 06:23 PM


All times are GMT +1. The time now is 10:12 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"