VBA - Create New Worksheet from list
I need some excel 2012 VBA help please.
Table2 in the worksheet named "Index" has employee information.
The code below reads the list and creates a new worksheet and renames it based on contents in column e and increments to the next This code works for new set up.
The next step I need help with is this. I want to add additonal employees. Could be 1 or 100 at a time. I need to either mod this code or create a new sub, either is fine with me.
1 - I would like for the code to find the new entries and create new worksheets based on the new entry only and thus skipping already created worksheets. There is very low risk of getting a worksheet with the same name as all cell values in column e are unique. I know worksheets have a 31 charater limit, but I am not worried it will be an issue for this project.
2 - The new worksheets will be created based also on a template named "template" is was done in the below code.
3 - Table looks like this :</SPAN>
</SPAN>
Thanks.</SPAN>
MrKen
---------------
[TABLE="width: 415"]
<TBODY>[TR]
[TD]Employee ID</SPAN>
[/TD]
[TD]First </SPAN>
[/TD]
[TD]2nd </SPAN>
[/TD]
[TD]Last </SPAN>
[/TD]
[TD]Worksheet Name</SPAN>
[/TD]
[/TR]
[TR]
[TD]B87687</SPAN>
[/TD]
[TD]Ronny</SPAN>
[/TD]
[TD]Karl</SPAN>
[/TD]
[TD]Fernández</SPAN>
[/TD]
[TD]FernándezB87687</SPAN>
[/TD]
[/TR]
</TBODY>[/TABLE]
</SPAN>
I need some excel 2012 VBA help please.
Table2 in the worksheet named "Index" has employee information.
The code below reads the list and creates a new worksheet and renames it based on contents in column e and increments to the next This code works for new set up.
The next step I need help with is this. I want to add additonal employees. Could be 1 or 100 at a time. I need to either mod this code or create a new sub, either is fine with me.
1 - I would like for the code to find the new entries and create new worksheets based on the new entry only and thus skipping already created worksheets. There is very low risk of getting a worksheet with the same name as all cell values in column e are unique. I know worksheets have a 31 charater limit, but I am not worried it will be an issue for this project.
2 - The new worksheets will be created based also on a template named "template" is was done in the below code.
3 - Table looks like this :</SPAN>
</SPAN>
Thanks.</SPAN>
MrKen
---------------
[TABLE="width: 415"]
<TBODY>[TR]
[TD]Employee ID</SPAN>
[/TD]
[TD]First </SPAN>
[/TD]
[TD]2nd </SPAN>
[/TD]
[TD]Last </SPAN>
[/TD]
[TD]Worksheet Name</SPAN>
[/TD]
[/TR]
[TR]
[TD]B87687</SPAN>
[/TD]
[TD]Ronny</SPAN>
[/TD]
[TD]Karl</SPAN>
[/TD]
[TD]Fernández</SPAN>
[/TD]
[TD]FernándezB87687</SPAN>
[/TD]
[/TR]
</TBODY>[/TABLE]
Code:
Sub CreateSheetsFromList()
Application.ScreenUpdating = False
Dim employeeCell As Range, employeeIDcol As Range
Set employeeIDcol = Sheets("index").Range("e2")
Set employeeIDcol = Range(employeeIDcol, employeeIDcol.End(xlDown))
For Each employeeCell In employeeIDcol
Sheets("template").Select ' Select the templete as the new worksheet to create
Sheets("template").Copy After:=Sheets(Sheets.Count) 'Creates a new worksheet based on the template. Worksheet will be named templete(1), (2) ect....
Sheets(Sheets.Count).Name = employeeCell.Value ' Renames the worksheets from the index of employees.
Range("R2").Select ' Select cell with employee ID number
Selection.Copy 'Copy cell with employee ID number
Range("J3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False ' Paste as a value the employee ID number in J3
Application.CutCopyMode = False ' Deselect the copy
Range("A1").Select
Next employeeCell
Application.ScreenUpdating = True
End Sub
Last edited: