Hi Gti182
This Code is in the attached and appears to do as you require
Option Explicit
Sub Do_Stuff()
Dim wb As Workbook
Dim newBook As Workbook
Dim ws As Worksheet
Dim LR As Long
Dim cel As Range
Dim myPath As String
myPath = ThisWorkbook.Path & "\"
Set wb = ThisWorkbook
Set ws = wb.Sheets("Original")
Application.ScreenUpdating = False
If Not Evaluate("ISREF(Lists!A1)") Then
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Lists"
Else
Sheets("Lists").Cells.Clear
End If
With ws
LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
.Sort.SortFields.Clear
.Sort.SortFields.Add(Range("D2:D" & LR), _
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, 0, 0)
.Sort.SortFields.Add(Range("D2:D" & LR), _
xlSortOnCellColor, xlDescending, , xlSortNormal).SortOnValue.Color = RGB(0, 176, 80)
.Sort.SortFields.Add Key:=Range("C2:C" & LR), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With .Sort
.SetRange Range("A2:D" & LR)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
.Columns(2).Copy Sheets("Lists").Range("A1")
Sheets("Lists").Columns("A:A").RemoveDuplicates Columns:=1, Header:=xlYes
ActiveWorkbook.Names.Add Name:="Depts", RefersTo:= _
"=OFFSET(Lists!$A$2,0,0,(COUNTA(Lists!$A:$A)-1),1)"
For Each cel In Range("Depts")
.Range("A1:D" & LR).AutoFilter Field:=2, Criteria1:=cel
Set newBook = Workbooks.Add(xlWBATWorksheet)
With newBook
With ws.Range("A1:D" & LR)
.Copy
newBook.Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteColumnWidths
newBook.Sheets(1).Range("A1").PasteSpecial Paste:=xlPasteAll
newBook.Sheets(1).Name = cel
End With
Application.DisplayAlerts = False
.SaveAs myPath & cel, FileFormat:=51
Application.DisplayAlerts = True
.Close False
End With
Next cel
.AutoFilterMode = False
Application.DisplayAlerts = False
Sheets("Lists").Delete
Application.DisplayAlerts = True
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Bookmarks