Steve DeWeese
New Member
I have a master workbook that has data for numerous locations. One sheet is a summary sheet and two additional sheets are backup detail. I am using the following VBA code that I found from another Chandoo lesson to 'break my list" into separate files for each location. That part works great but I need to add code that will also copy the supporting detail from the other two sheets in the master sheet and add them to each of the individual location workbooks. It would be ideal if the code would pull only the detail for that same location but it is fine if it copies the entire sheets to the new file. Here is what I have now:
Sub breakMyList()
' This macro takes values in the range myList
' and breaks it in to multiple lists
' and saves them to separate files.
Dim cell As Range
Dim curPath As String
curPath = ActiveWorkbook.Path & "\"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each cell In Range("lstClinic")
[valClinic] = cell.Value
Range("myList").AdvancedFilter Action:=xlFilterCopy, _
criteriarange:=Range("Criteria"), copyToRange:=Range("Extract"), unique:=False
Range(Range("Extract"), Range("Extract").End(xlDown)).Copy
Workbooks.Add
ActiveSheet.Paste
ActiveWorkbook.SaveAs Filename:=curPath & cell.Value & Format(Now, "dmmmyyyy-hhmmss") & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
Range(Range("Extract"), Range("Extract").End(xlDown)).ClearContents
Next cell
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
The additional sheets I would like to copy are named "Surgery Details" and "Surgery Days" in the master workbook. Column A in each of these sheets has the name of the location. Row 1 has a header and the data begins in row 2.
Any help would be greatly appreciated.
Sub breakMyList()
' This macro takes values in the range myList
' and breaks it in to multiple lists
' and saves them to separate files.
Dim cell As Range
Dim curPath As String
curPath = ActiveWorkbook.Path & "\"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each cell In Range("lstClinic")
[valClinic] = cell.Value
Range("myList").AdvancedFilter Action:=xlFilterCopy, _
criteriarange:=Range("Criteria"), copyToRange:=Range("Extract"), unique:=False
Range(Range("Extract"), Range("Extract").End(xlDown)).Copy
Workbooks.Add
ActiveSheet.Paste
ActiveWorkbook.SaveAs Filename:=curPath & cell.Value & Format(Now, "dmmmyyyy-hhmmss") & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
Range(Range("Extract"), Range("Extract").End(xlDown)).ClearContents
Next cell
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
The additional sheets I would like to copy are named "Surgery Details" and "Surgery Days" in the master workbook. Column A in each of these sheets has the name of the location. Row 1 has a header and the data begins in row 2.
Any help would be greatly appreciated.