Hi, I'm not a VBA person, but tried to take a stab piecing together bits from other posts, but didn't do too well.
I have a worksheet Range A - Z.
Column C is filled with manager names (multiple entries of same manager name as each line represents an employee who reports to a manager, Multiple employees per manager)
I need the code to filter the list by each manager, copy the range for each and paste into a separate workbook (not as values, as is). then save the workbook as "Text workbook & Manager Name)
loop through all managers and do this for every manager on the list.
I cant save a test file here because security wont allow this or upload of code. Below is what I pieced together, I know its not correct, but some of the elements work.
I have a worksheet Range A - Z.
Column C is filled with manager names (multiple entries of same manager name as each line represents an employee who reports to a manager, Multiple employees per manager)
I need the code to filter the list by each manager, copy the range for each and paste into a separate workbook (not as values, as is). then save the workbook as "Text workbook & Manager Name)
loop through all managers and do this for every manager on the list.
I cant save a test file here because security wont allow this or upload of code. Below is what I pieced together, I know its not correct, but some of the elements work.
VBA Code:
Sub FilterCopyPaste()
Dim wb As Workbook
Dim Ash As Worksheet
Dim Cws As Worksheet
Dim FilterRange As Range
Dim filteredData As Range
Dim managerCell As Range
Dim newWorkbook As Workbook
Dim newFilePath As String
Dim Rcount As Long
Dim Rnum As Long
Dim FieldNum As Integer
Dim mailAddress As String
Dim strbody As String
Dim DefaultSignature As String
' Set the workbook and worksheet variables
Set wb = ThisWorkbook
Set Ash = wb.ActiveSheet
'Set filter range and filter column (Column with names)
Set FilterRange = Ash.Range("A1:Z" & Ash.Rows.Count)
FieldNum = 3
'Count of the unique values + the header cell
Rcount = Application.WorksheetFunction.CountA(Ash.Columns(3))
'If there are unique values start the loop
If Rcount >= 2 Then
For Rnum = 2 To Rcount
'Filter the FilterRange on the FieldNum column
FilterRange.AutoFilter Field:=FieldNum, _
Criteria1:=Ash.Cells(Rnum, 1).Value
'Add a worksheet for the unique list and copy the unique list in A1
Set newWorkbook = Workbooks.Add
FilterRange.Columns(FieldNum).AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=Ash.Range("A1"), _
CriteriaRange:="", Unique:=True
newWorkbook.Worksheets(1).Range("A1").Paste Paste:=xlPaste
' Save the new workbook with the department value
newWorkbook.SaveAs wb.Path & "\" & "Compensation Increase Master Sheet" & ".xlsx"
newWorkbook.Close SaveChanges:=False
Next Rnum
Application.ScreenUpdating = False
'Close AutoFilter
Ash.AutoFilterMode = False
' Activate the original workbook
wb.Activate
End If
End Sub