Hello, I need help with the macro. I recorded the macro and it works fine. It is not as dynamic as I want it to be. If I need to add/delete worksheet, I will have to edit the macro which I don't want to do. What I need is to modify the following macro using a loop and using a name range, such as "reportsheets", for those sheets listed within the workbook. The workbook has about 95 sheets that includes all the data and reporting sheets.
The macro does the following:
- Make copy of all the "reportsheets" and paste special value to a new workbook
- Deletes name ranges in the new workbook except for "Print_Title" & "Print_Area" which I need
- Saves the file referencing "PathSave & FilenameSave" for file name and close
- Keeps the original workbook open
I would like a loop macro to do the above function. Hope I was clear enough.
Let me know if any further questions for clarification.
>>> use code - tags <<<
The macro does the following:
- Make copy of all the "reportsheets" and paste special value to a new workbook
- Deletes name ranges in the new workbook except for "Print_Title" & "Print_Area" which I need
- Saves the file referencing "PathSave & FilenameSave" for file name and close
- Keeps the original workbook open
I would like a loop macro to do the above function. Hope I was clear enough.
Let me know if any further questions for clarification.
>>> use code - tags <<<
Code:
Dim PathSave As String
Dim FilenameSave As String
PathSave = Range("B3").Value
FilenameSave = Range("B4").Value
Application.ScreenUpdating = False
Sheets(Array("Cover", "Sum1", "Sum2", "Comp1", "Mix1", "StrWk1", "Comp2", "Mix2", _
"StrWk2", "Comp3", "Mix3", "StrWk3", "Comp4", "Mix4", "StrWk4", "Comp5", "Mix5", _
"StrWk5", "Comp6", "Mix6", "StrWk6", "Comp7", "Mix7", "StrWk7", "Comp8", "Mix8", _
"StrWk8", "Comp9", "Mix9", "StrWk9", "Comp10", "Mix10", "StrWk10", "Comp11", "Mix11", _
"StrWk11", "Comp13", "Mix13", "StrWk13", "Comp14", "Mix14", "StrWk14", "Comp15", _
"Mix15", "StrWk15", "Comp17", "Mix17", "StrWk17", "Comp18", "Mix18", "StrWk18", _
"Comp19", "Mix19", "StrWk19", "Comp20", "Mix20", "StrWk20", "Comp21", "Mix21", _
"StrWk21")).Select
Sheets("Cover").Activate
Sheets(Array("Cover", "Sum1", "Sum2", "Comp1", "Mix1", "StrWk1", "Comp2", "Mix2", _
"StrWk2", "Comp3", "Mix3", "StrWk3", "Comp4", "Mix4", "StrWk4", "Comp5", "Mix5", _
"StrWk5", "Comp6", "Mix6", "StrWk6", "Comp7", "Mix7", "StrWk7", "Comp8", "Mix8", _
"StrWk8", "Comp9", "Mix9", "StrWk9", "Comp10", "Mix10", "StrWk10", "Comp11", "Mix11", _
"StrWk11", "Comp13", "Mix13", "StrWk13", "Comp14", "Mix14", "StrWk14", "Comp15", _
"Mix15", "StrWk15", "Comp17", "Mix17", "StrWk17", "Comp18", "Mix18", "StrWk18", _
"Comp19", "Mix19", "StrWk19", "Comp20", "Mix20", "StrWk20", "Comp21", "Mix21", _
"StrWk21")).Copy
Sheets(Array("Cover", "Sum1", "Sum2", "Comp1", "Mix1", "StrWk1", "Comp2", "Mix2", _
"StrWk2", "Comp3", "Mix3", "StrWk3", "Comp4", "Mix4", "StrWk4", "Comp5", "Mix5", _
"StrWk5", "Comp6", "Mix6", "StrWk6", "Comp7", "Mix7", "StrWk7", "Comp8", "Mix8", _
"StrWk8", "Comp9", "Mix9", "StrWk9", "Comp10", "Mix10", "StrWk10", "Comp11", "Mix11", _
"StrWk11", "Comp13", "Mix13", "StrWk13", "Comp14", "Mix14", "StrWk14", "Comp15", _
"Mix15", "StrWk15", "Comp17", "Mix17", "StrWk17", "Comp18", "Mix18", "StrWk18", _
"Comp19", "Mix19", "StrWk19", "Comp20", "Mix20", "StrWk20", "Comp21", "Mix21", _
"StrWk21")).Select
Sheets("Cover").Activate
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Range("A1").Select
Sheets("Cover").Select
ActiveWorkbook.Names("District").Delete
ActiveWorkbook.Names("DistrictName").Delete
ActiveWorkbook.Names("FiscalWks").Delete
ActiveWorkbook.Names("FYLY").Delete
ActiveWorkbook.Names("FYTY").Delete
ActiveWorkbook.Names("LOCATN").Delete
ActiveWorkbook.Names("NonComp").Delete
ActiveWorkbook.Names("PdWk").Delete
ActiveWorkbook.Names("Period").Delete
ActiveWorkbook.Names("StoreList").Delete
ActiveWorkbook.Names("week").Delete
ActiveWorkbook.Names("WkEndDate").Delete
ActiveWorkbook.Names("WkNum").Delete
ActiveWorkbook.SaveAs PathSave & FilenameSave, FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close
Sheets("MacroSheet").Select
Range("A15").Select
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: