Copy Template multiple times and rename using list

Macroless99

New Member
Joined
Nov 1, 2014
Messages
3
Hi All

I need some help with VBA code to copy a template tab multiple times and rename each new tab from a list.
* My template tab is called StudentA
* My list is in a tab Data Input cells A4:A50

What I currently have is:

Code:
[/COLOR]

Sub Copy_Sheets()
    Dim i As Integer
    Dim wks As Worksheet
     
    Set wks = Sheets("DataInput")
     
    For i = 4 To 50
        Sheets("StudentA").Copy After:=Sheets(6)
        ActiveSheet.Name = wks.Cells(i, 1)
        ActiveSheet.Cells(1, 2) = wks.Cells(i, 1)
    Next
End Sub[COLOR=#333333]

When I run it, it copies the template tab once but doesn't rename and returns a message "400".

Would really appreciate any help you can give me!!!


Kirsty
 

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.
What line is highlighted when you get the error 400?


Is it "Data Input" or "DataInput"?
 
Upvote 0
Oops missed the first part. It's not automatically going into debug mode and nothing is being highlighted. I have been assuming it is one of these lines because it is performing the copy of the "StudentA" tab but not renaming the tab before giving me the error:



Code:
ActiveSheet.Name = wks.Cells(i, 1)        
ActiveSheet.Cells(1, 2) = wks.Cells(i, 1)
 
Upvote 0
Oops missed the first part. It's not automatically going into debug mode and nothing is being highlighted. I have been assuming it is one of these lines because it is performing the copy of the "StudentA" tab but not renaming the tab before giving me the error:
Code:
ActiveSheet.Name = wks.Cells(i, 1)        
ActiveSheet.Cells(1, 2) = wks.Cells(i, 1)

I have run the code as is and it works.

Like you said, the sheet is created but probably not renamed, so I would suggest you check the "range/cell" the sheet name is being sourced from

Check what the value of "I" is when the code stops and identify the content of wks.cells(I,1)

Confirm that the cell(e.g A4) is not blank or contains some "illegal" characters
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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