Link to home
Start Free TrialLog in
Avatar of cookiejest
cookiejest

asked on

Copy a sheet rename it from a list and add values in some cells

I need a macro in excel that copys a sheet called "template" for each value in a list.

each new sheet should then be named by the value in the list AND a cell within the sheet should have the name copied to it.

It sounds likea  simple task, any help please?

Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

SOmething like the following which is code in the specific workbook:

Chris
Sub nuSheets()
Dim sh As Worksheet

For Each nam In Array("fred", "doris")
    Sheets("Template").Copy After:=Sheets(Sheets.Count)
    With Sheets(Sheets.Count)
        .Name = nam
        .Range("a1").Value = Name
    End With
Next

End Sub

Open in new window

Avatar of cookiejest
cookiejest

ASKER

Ok that is almost what I need, can you explain where I would input the array A2:A45 within my sheet called "Tracking Sheet".

I assume a1 is the cell where the sheet name is pasted within it.
The sheet copy takes all the data from template ... Is your array a vba array that needs to be placed in the copy and if so how is it defined?

Yes a1 is the cell with the sheet name ... Albeit a typo fixed below.

Let me know re tha array and I will modify accordingly

Chris
Sub nuSheets()
Dim sh As Worksheet

For Each nam In Array("fred", "doris")
    Sheets("Template").Copy After:=Sheets(Sheets.Count)
    With Sheets(Sheets.Count)
        .Name = nam
        .Range("a1").Value = Nam
    End With
Next

End Sub

Open in new window

Re-reading it looks as though the 'array' to be copied is the range a2:a45 of sheet tracking data therefore:

Chris
Sub nuSheets()
Dim sh As Worksheet

For Each Nam In Array("fred", "doris")
    Sheets("Template").Copy After:=Sheets(Sheets.Count)
    With Sheets(Sheets.Count)
        .Name = Nam
        .Range("a1").Value = Nam
        Sheets("Tracking Sheet").Range("a2:a45").Copy .Range("a2:a45")
    End With
Next

End Sub

Open in new window

No each item in the array (which is in cells a2:a45) needs a sheet that is based on the "template". The name of the sheet is the name of the item in the array. The same value also needs to be placed within a cell in its newly created sheet
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial