Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 193
Default make copies of sheet and name them from list

Hello,
I have about 50 employee numbers in sheet1 A:A. Is there code for a macro
that can make a copy of sheet2 for each instance of employee number and name
it with the employee number as the sheet name?

thanks in advance for any help,
Robert
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default make copies of sheet and name them from list

Edit sheet names to suit where noted.

Sub CreateNameSheets()
' by Dave Peterson
' List sheetnames required in col A in a sheet: List
' Sub will copy sheets based on the sheet named as: Template
' and name the sheets accordingly

Dim TemplateWks As Worksheet
Dim ListWks As Worksheet
Dim ListRng As Range
Dim mycell As Range

Set TemplateWks = Worksheets("Template") 'change to "Sheet2"
Set ListWks = Worksheets("list") 'Change to "Sheet1"
With ListWks
Set ListRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

For Each mycell In ListRng.Cells
TemplateWks.Copy After:=Worksheets(Worksheets.Count)
On Error Resume Next
ActiveSheet.Name = mycell.Value
If Err.Number < 0 Then
MsgBox "Please fix: " & ActiveSheet.Name
Err.Clear
End If
On Error GoTo 0
Next mycell

End Sub


Gord Dibben MS Excel MVP

On Thu, 9 Jul 2009 16:01:04 -0700, Robert
wrote:

Hello,
I have about 50 employee numbers in sheet1 A:A. Is there code for a macro
that can make a copy of sheet2 for each instance of employee number and name
it with the employee number as the sheet name?

thanks in advance for any help,
Robert


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,124
Default make copies of sheet and name them from list

Why not just use datafilterautofilter?

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Robert" wrote in message
...
Hello,
I have about 50 employee numbers in sheet1 A:A. Is there code for a macro
that can make a copy of sheet2 for each instance of employee number and
name
it with the employee number as the sheet name?

thanks in advance for any help,
Robert


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,346
Default make copies of sheet and name them from list

Hi,

Well I finally get a use for this featu

1. Higlight the employee numbes in Column A and choose Data, Pivot Table and
Pivot Chart Report, click Next, Next and choose Existing worksheet and pick
an empty range starting on row 3 or lower, say D4, and click Finish.
2. Drop the title for the Employee # field in the Page Field area.
3. With the pivot table selected choose PivotTable, Show Pages and click OK.

4. Since you probably don't need the pivot tables, select the first employee
sheet tab, how down the shift key and click the last employee sheet tab.
5. Select the range with the pivot tables (empty ones) and press Delete.


--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire


"Robert" wrote:

Hello,
I have about 50 employee numbers in sheet1 A:A. Is there code for a macro
that can make a copy of sheet2 for each instance of employee number and name
it with the employee number as the sheet name?

thanks in advance for any help,
Robert

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 193
Default make copies of sheet and name them from list

Thanks Gord! It worked...there were a few errors "Please fix", but I just
kept cancelling and it took off and made all the sheets. Just for fun, I
tried to change the range to A6:A51 where the actual numbers are but I got VB
errors. Maybe the headers rows gave problems. I should have been more
specific. In any case, this saved me tons of time and I very much appreciate
it!
Robert

"Gord Dibben" wrote:

Edit sheet names to suit where noted.

Sub CreateNameSheets()
' by Dave Peterson
' List sheetnames required in col A in a sheet: List
' Sub will copy sheets based on the sheet named as: Template
' and name the sheets accordingly

Dim TemplateWks As Worksheet
Dim ListWks As Worksheet
Dim ListRng As Range
Dim mycell As Range

Set TemplateWks = Worksheets("Template") 'change to "Sheet2"
Set ListWks = Worksheets("list") 'Change to "Sheet1"
With ListWks
Set ListRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

For Each mycell In ListRng.Cells
TemplateWks.Copy After:=Worksheets(Worksheets.Count)
On Error Resume Next
ActiveSheet.Name = mycell.Value
If Err.Number < 0 Then
MsgBox "Please fix: " & ActiveSheet.Name
Err.Clear
End If
On Error GoTo 0
Next mycell

End Sub


Gord Dibben MS Excel MVP

On Thu, 9 Jul 2009 16:01:04 -0700, Robert
wrote:

Hello,
I have about 50 employee numbers in sheet1 A:A. Is there code for a macro
that can make a copy of sheet2 for each instance of employee number and name
it with the employee number as the sheet name?

thanks in advance for any help,
Robert



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
make multiple copies of a sheet in a new workbook galeanne Excel Worksheet Functions 4 April 9th 23 12:50 PM
make copies of worksheet for each day of month Rhett C Excel Discussion (Misc queries) 1 October 29th 08 02:29 AM
Make dropdown item list in invoice sheet tim New Users to Excel 2 March 7th 08 07:47 PM
how to make a filtered list on a different sheet Madduck Excel Discussion (Misc queries) 4 August 22nd 07 11:42 AM
How can I Make 3 copies of one worksheet Page? VHall Excel Worksheet Functions 1 July 2nd 06 07:05 PM


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