VBA - Adding a New Worksheet, Naming with Cell Reference in Source Sheet

jcoleman5534

New Member
Joined
Jul 12, 2013
Messages
9
Hello-

Here's what I'm trying to do....

I have ~2250 names in SheetA, Column A (Cells A1:A2250). I need VBA to add 2250 worksheets for each of the names in the Column. When it adds the new worksheet I need cell B7 in each of the new worksheets filled by with the names from cell A1 then A2 then A3 and so on for every sheet that is added. Additionally, it would be great to have the sheet names also equal cell B7.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Welcome to the Board!

Here's one way:

<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> AddSheets()<br>****<SPAN style="color:#00007F">Dim</SPAN> c <SPAN style="color:#00007F">As</SPAN> Range<br>****<br>********<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> c <SPAN style="color:#00007F">In</SPAN> Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)<br>************Worksheets.Add After:=Sheets(Sheets.Count)<br>************<SPAN style="color:#00007F">With</SPAN> ActiveSheet<br>****************.Name = c.Value<br>****************.Range("B7").Value = c.Value<br>************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>********<SPAN style="color:#00007F">Next</SPAN> c<br>********<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Note that the code doesn't take potential duplicates names into account, in which case it will bomb. If there can be duplicates, you'll need to indicate how you want to manage that.

HTH,
 
Upvote 0
Hello-

Here's what I'm trying to do....

I have ~2250 names in SheetA, Column A (Cells A1:A2250). I need VBA to add 2250 worksheets for each of the names in the Column. When it adds the new worksheet I need cell B7 in each of the new worksheets filled by with the names from cell A1 then A2 then A3 and so on for every sheet that is added. Additionally, it would be great to have the sheet names also equal cell B7.

Ok, so if I want to perform the same function except applying formatting of a current sheet with the macro that adds the new sheets how do I implement?
 
Upvote 0
In other words, I have a sheet that is formatted a certain way that I just want to create copies of with the new list of names input rather than simply copied.

Does that make sense?
 
Upvote 0
In other words, I have a sheet that is formatted a certain way that I just want to create copies of with the new list of names input rather than simply copied.

Does that make sense?

You can use:

Sheets("Master").Copy After:=Sheets(Sheets.Count)

Just note that there is a known bug in Excel that it will hiccup after programmatically copying x number of sheets. Microsoft documents a workaround here: Copying worksheet programmatically causes run-time error 1004 in Excel
 
Upvote 0
Replace the Worksheets.Add portion with it.

Note that you'll need to change the "Master" sheet name as it relates to your workbook.
 
Upvote 0

Forum statistics

Threads
1,214,631
Messages
6,120,640
Members
448,974
Latest member
DumbFinanceBro

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