Macro to Create Worksheets from a List

MarkReddell

Board Regular
Joined
Sep 1, 2011
Messages
210
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hello Excel guru's!!! I need help in writing a macro to create a worksheet based on an entry in sheet named: Employee's. Within this sheet in Col. D4:d103 is a list of employee ID number. Upon an entry I need a sheet to be created with the employee ID number by copying the sheet named: Mater Sheet. Is this even possible??? Help Please!!! :confused::confused::confused:
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
You said:

"Upon an entry I need a sheet to be created"

Do you mean anytime you enter a value into column "D" you want this sheet created automatically?
Or do you mean you want all these sheets created when you run the macro?

And are you sure the sheet is named "Mater Sheet"

Or do you mean sheet is named "Master"

Put the sheet name in quotes:
 
Last edited:
Upvote 0
You said:

"Upon an entry I need a sheet to be created"

Do you mean anytime you enter a value into column "D" you want this sheet created automatically?
Or do you mean you want all these sheets created when you run the macro?

And are you sure the sheet is named "Mater Sheet"

Or do you mean sheet is named "Master"

Put the sheet name in quotes:
Yes! I need anytime a make an entry that the macro creates a ws in the emp. id # as the new ws. And, u r correct the sheet is: Master Sheet.
 
Upvote 0
So why do we need to use rows 4 to 103

If you want the sheet created immediately after you enter a value into column "D" why do we need to restrict this to rows 4 to 103

And you said:
And, u r correct the sheet is: Master Sheet.

I said put the sheet name in quotes.

Is the sheet named "Master" or "Master Sheet"

And having this done immediately after you enter a value in column "D" may be dangerous. If you enter "Dog" into Column "D" a sheet named "Dog" will automatically be made.
 
Upvote 0
Ok.
Here is what you asked for:
When ever you enter any value into column "D" in the Range("D4:D103")
The sheet named "Master" will be copied and named what ever value you entered into column "D"

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet Named "Employee's tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D4:D103")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Sheets("Master").Copy After:=Sheets(Worksheets.Count)
ActiveSheet.Name = Target.Value
End If
End Sub

This will not create a whole list of new sheets like you said here:
"Within this sheet in Col. D4:d103 is a list of employee ID number"

This script will only create a new sheet when you manually enter a value in column "D"

That's why I asked if you wanted this to happen when you run the script or happen automatically when you enter a id# and you said I want this to happen automatically when you enter a value.
 
Last edited:
Upvote 0
Ok.
Here is what you asked for:
When ever you enter any value into column "D" in the Range("D4:D103")
The sheet named "Master" will be copied and named what ever value you entered into column "D"

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet Named "Employee's tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D4:D103")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Sheets("Master").Copy After:=Sheets(Worksheets.Count)
ActiveSheet.Name = Target.Value
End If
End Sub

This will not create a whole list of new sheets like you said here:
"Within this sheet in Col. D4:d103 is a list of employee ID number"

This script will only create a new sheet when you manually enter a value in column "D"

That's why I asked if you wanted this to happen when you run the script or happen automatically when you enter a id# and you said I want this to happen automatically when you enter a value.
Thank You very Much! This worx perfectly!!! Have a Blessed Day!!!
 
Upvote 0
Glad to hear it works for you.
I added a couple lines of code to warn you if that sheet has already been made.
Use this script

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D4:D103")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
On Error GoTo M
Sheets("Master").Copy After:=Sheets(Worksheets.Count)
ActiveSheet.Name = Target.Value
Sheets("Employee's").Activate
End If
Exit Sub
M:
MsgBox "That sheet allready exist"
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
Sheets("Employee's").Activate
End Sub
 
Last edited:
Upvote 0
Glad to hear it works for you.
I added a couple lines of code to warn you if that sheet has already been made.
Use this script

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D4:D103")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
On Error GoTo M
Sheets("Master").Copy After:=Sheets(Worksheets.Count)
ActiveSheet.Name = Target.Value
Sheets("Employee's").Activate
End If
Exit Sub
M:
MsgBox "That sheet allready exist"
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
Sheets("Employee's").Activate
End Sub


How would you add this code to your macro???

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$F$1" Then Exit Sub
Application.Run Target.Value
End Sub

Thanx 4 your help!!! :confused::confused::confused:
 
Upvote 0
So you only want the script to run if a change is made to range ("F1") is that what you want?

I'm not sure what this line of code does:
"Application.Run Target.Value"

How would you add this code to your macro???

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$F$1" Then Exit Sub
Application.Run Target.Value
End Sub

Thanx 4 your help!!! :confused::confused::confused:
 
Last edited:
Upvote 0
If the answer to my question is yes.
Try this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("F1")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
On Error GoTo M
Sheets("Master").Copy After:=Sheets(Worksheets.Count)
ActiveSheet.Name = Target.Value
Sheets("Employee's").Activate
End If
Exit Sub
M:
MsgBox "That sheet allready exist"
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
Sheets("Employee's").Activate
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,244
Messages
6,170,976
Members
452,372
Latest member
Natalie18

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top