Help with Code

Ged Traynor

Board Regular
Joined
Oct 12, 2007
Messages
73
Hi All

Just wondering if some could help me with some code. Basically what I'm trying to do is have a sheet called "Dates" with a range that contains a list of dates in it, for example A1:A30
I need VBA Code to look at this date range and copy a sheet called "Template", so if A1 contains 16/06/2011 the code will copy the "Template" sheet and rename it to the value of cell A1 etc

I tried using the below code, which works to a certain extent, but I do get an error on this line Sheets(Sheets.Count).Name = Item
How can I modify the code to copy the "Templates" sheet and rename it as above.

Sub CreateAndNameWorksheets()
Sheets("Dates").Select
Words = Cells.Range("A1:A23")
For Each Item In Words
Sheets.Add After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = Item
Next Item
End Sub

Thanks in Advance
Ged Traynor
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

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