Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50163

macro duplicate file and change tab name loop

$
0
0
Hi,

I have one master file with 3 sheets and I need to duplicate this workook 100 times and saving it based on a list of names. i'm hoping a macro can help me do this.

example:

sheet 1
sheet 2
sheet 3 - called sheetlist

in sheet 3 i have a list of names in collumn A
100
200
300
400
.
.

I need it to look at the list and rename sheet 2 to 100 and then do a savefile as 100. then this would continue down the list.

i started on a macro with a loop but it is not working please see below. hopefully someone can help me with my code

Code:

Sub Detailsummary()
Dim ws As Worksheet
Dim i As Long
Dim sname As String
Dim tname As String
Dim lastrow As Long
Dim ThisFile As String
Dim icostcentre As String


For i = 3 To Worksheets("sheetlist").Range("A" & Rows.Count).End(xlUp).Row + 1
    'With Worksheets(i - 1)
        sname = Worksheets("sheetlist").Range("A" & i - 1).Value
        tname = Worksheets("sheetlist").Range("A" & i - 2).Value
        Sheets(tname).Select
        ActiveSheet.Name = sname
        ThisFile = Worksheets("sheetlist").Range("A" & i - 1).Value
        Application.DisplayAlerts = False
        Worksheets("sheetlist").Delete
        Application.DisplayAlerts = True
        ThisWorkbook.SaveAs Filename:=ThisFile
        'ActiveWorkbook.Close
        'MsgBox ("sname" & sname)
        'MsgBox ("tname" & tname)

       
       
       
    'End With
Next i
End Sub


Viewing all articles
Browse latest Browse all 50163

Trending Articles