diygail123
New Member
- Joined
- Oct 24, 2018
- Messages
- 25
Hi guys
I am trying to write a macro that will copy a worksheet, then save it using the worksheet name as the filename. I then want it to go to other worksheets, in the same workbook, and do the same. I was trying to use a list of names typed on a worksheet (List of Names) to tell the macro which worksheets to copy, but Im not having much luck! I need the macro to scroll through said worksheets, creating a copy, and saving, using the worksheet name as a filename. See below for as far as I have got. Dont laugh, Im a beginner! The save isnt working, its naming it as the sheet I started on (called Macro), and I dont know how to get it to loop through the names on the list
Sub CopySave2()
'DECLARE VARIABLES
Dim StrFileName As String
StrFileName = ActiveSheet.Name & ".xlsx"
Dim ListOfNames As Range, c As Range
Set ListOfNames = Worksheets("List of Names").Range("b2:b20") 'BRIAN KRAL IS THE FIRST WORKSHEET I WANT TO COPY BUT I DONT KNOW HOW TO PUT THIS IN THE CODE WITHOUT STATING THE NAME!
'For Each c??
'MAKE A COPY OF FIRST WORKSHEET ON THE LIST, TO A NEW WORKBOOK
Sheets("BRIAN KRAL").Copy
'ADD TWO WORKSHEETS AND NAME THEM "DETAILS" & "PIVOT"
Sheets.Add After:=ActiveSheet
Sheets.Add After:=ActiveSheet
Sheets("Sheet3").Name = "Details"
Sheets("Sheet2").Name = "Pivot"
'SAVE THE WORKBOOK
ActiveWorkbook.SaveAs StrFileName
Next c
I am trying to write a macro that will copy a worksheet, then save it using the worksheet name as the filename. I then want it to go to other worksheets, in the same workbook, and do the same. I was trying to use a list of names typed on a worksheet (List of Names) to tell the macro which worksheets to copy, but Im not having much luck! I need the macro to scroll through said worksheets, creating a copy, and saving, using the worksheet name as a filename. See below for as far as I have got. Dont laugh, Im a beginner! The save isnt working, its naming it as the sheet I started on (called Macro), and I dont know how to get it to loop through the names on the list
Sub CopySave2()
'DECLARE VARIABLES
Dim StrFileName As String
StrFileName = ActiveSheet.Name & ".xlsx"
Dim ListOfNames As Range, c As Range
Set ListOfNames = Worksheets("List of Names").Range("b2:b20") 'BRIAN KRAL IS THE FIRST WORKSHEET I WANT TO COPY BUT I DONT KNOW HOW TO PUT THIS IN THE CODE WITHOUT STATING THE NAME!
'For Each c??
'MAKE A COPY OF FIRST WORKSHEET ON THE LIST, TO A NEW WORKBOOK
Sheets("BRIAN KRAL").Copy
'ADD TWO WORKSHEETS AND NAME THEM "DETAILS" & "PIVOT"
Sheets.Add After:=ActiveSheet
Sheets.Add After:=ActiveSheet
Sheets("Sheet3").Name = "Details"
Sheets("Sheet2").Name = "Pivot"
'SAVE THE WORKBOOK
ActiveWorkbook.SaveAs StrFileName
Next c
Last edited: