Hi 4gurus
Replace the Module1 Code with this...still not certain of your Sort Requirements
Public myArray() As Variant
Public Arr As Variant
Option Explicit
Sub DoStuff()
Dim WB As Workbook
Dim ws As Worksheet
Dim LR As Long, x As Long
Dim Rng As Range
Application.ScreenUpdating = False
If Not Evaluate("ISREF(Lists!A1)") Then
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Lists"
Sheets("Lists").Range("C1").Value = "Owners"
Else
Sheets("Lists").Cells.ClearContents
Sheets("Lists").Range("C1").Value = "Owners"
End If
Set ws = Sheets("RawData")
With ws
LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
.Range("A1:A" & LR).AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Sheets("Lists").Range("A1"), Unique:=True
ActiveWorkbook.Names.Add Name:="Owners", RefersTo:= _
"=OFFSET(Lists!$A$2,0,0,(COUNTA(Lists!$A:$A)-1),1)"
UserForm1.Show
Sheets("Lists").Range("C2").Resize(UBound(Arr, 1)) = WorksheetFunction.Transpose(Arr)
ActiveWorkbook.Names.Add Name:="MyOwners", RefersTo:= _
"=OFFSET(Lists!$C$1,0,0,(COUNTA(Lists!$C:$C)),1)"
.Range("A1:A" & LR).AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Sheets("Lists").Range("MyOwners"), Unique:=False
Set Rng = .Range("A1:H" & LR)
Application.SheetsInNewWorkbook = 1
Set WB = Workbooks.Add
Rng.SpecialCells(xlCellTypeVisible).Copy WB.Worksheets(1).Range("A1")
With WB
With Sheets("Sheet1")
.Name = "Extracted Data"
.Range("E:F").NumberFormat = "$#,##0"
.Columns(4).EntireColumn.Delete
.Columns(1).EntireColumn.Delete
LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
.Range("A1:F" & LR).AutoFilter Field:=5, Criteria1:="NA"
Set Rng = .AutoFilter.Range
x = Rng.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1
If x >= 1 Then
.Range("A2:A" & LR).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End If
.AutoFilterMode = False
.Range("A:F").Sort Key1:=Range("C2"), Order1:=xlDescending, Key2:=Range("D2") _
, Order2:=xlDescending, Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
End With
Application.DisplayAlerts = False
.SaveAs ThisWorkbook.Path & "\ Output" & ".xls", FileFormat:=xlNormal
Application.DisplayAlerts = True
.Close
End With
.ShowAllData
End With
Application.DisplayAlerts = False
Sheets("Lists").Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Sub CreateFilter()
Dim i As Long, n As Long
ReDim myArray(UserForm1.ListBox1.ListCount)
If UserForm1.ListBox1.ListIndex = -1 Then
MsgBox "You didn't select any Names"
End If
For i = 0 To UserForm1.ListBox1.ListCount - 1
If UserForm1.ListBox1.Selected(i) = True Then
myArray(n) = UserForm1.ListBox1.List(i)
n = n + 1
End If
Next i
ReDim Preserve myArray(n)
Arr = myArray
Unload UserForm1
End Sub
Bookmarks