bloomfieldhero
New Member
- Joined
- Jul 13, 2018
- Messages
- 2
I attached a dropbox link so its easy to follow along.
In this roster, I have a sheet labeled setup. In there aremanager names to reference, I want these three managers to be transferred intotheir own workbooks (individually: manager 1, manager 3, manager 5). In Sheet1,Column AR is where you can find the manager names, the rest of the data is justdummy data. I only want the employee data from the criteria in the "Setup" worksheet, nothing else.
I have a script that works when I copy andinsert copied cells into a new Column A (column AR managers), but that forcesextra tedious steps. Can I Just keep the worksheet as-is, and have this scriptreference column AR to-the Setup worksheet criteria? Or will I have to have my managerlist column be Column A for this to work?
Any idea how to do this?
In this roster, I have a sheet labeled setup. In there aremanager names to reference, I want these three managers to be transferred intotheir own workbooks (individually: manager 1, manager 3, manager 5). In Sheet1,Column AR is where you can find the manager names, the rest of the data is justdummy data. I only want the employee data from the criteria in the "Setup" worksheet, nothing else.
I have a script that works when I copy andinsert copied cells into a new Column A (column AR managers), but that forcesextra tedious steps. Can I Just keep the worksheet as-is, and have this scriptreference column AR to-the Setup worksheet criteria? Or will I have to have my managerlist column be Column A for this to work?
Code:
Sub Main()
Dim Managers, Manager
Dim Header As Range, Where As Range, This As Range
Dim Wb As Workbook
'Prepare
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Refer to the headings
Set Header = Range("A1").EntireRow
'Refer to the data in column A
Set Where = Range("A2", Range("A" & Rows.Count).End(xlUp))
'Get the managers
With Worksheets("Setup")
Set Managers = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
End With
'Loop through
For Each Manager In Managers
'Find them
Set This = FindAll(Where, Manager)
If This Is Nothing Then GoTo Skip
'Create a new file
Set Wb = Workbooks.Add(XlWBATemplate.xlWBATWorksheet)
With Wb
With .Sheets(1)
'Copy the header
Header.Copy .Range("A1")
'Copy the data
This.EntireRow.Copy .Range("A2")
End With
'Save it
.SaveAs ThisWorkbook.Path & Application.PathSeparator & Manager & Format(Date, "_mm_dd_yyyy") & "_Roster.xlsx", XlFileFormat.xlOpenXMLWorkbook
.Close
End With
Skip:
Next
'Done
End Sub
Any idea how to do this?