Tim Hanson
Member
I have a Advanced Filter Macro that copies Unique rows to a new sheet.
But it is not doing as I expect.
I want to move all rows where cells in a column are unique to that end I have set: CriteriaRange:=ws.Range("F2:F" & lRow)
But the macro is moving all rows that are unique only if every cell in a row is unique from all cells in any other row (I hope that make sense)
Do I misunderstand stand what CriteriaRange means?
Am I misusing Advanced Filter?
Thanks
But it is not doing as I expect.
I want to move all rows where cells in a column are unique to that end I have set: CriteriaRange:=ws.Range("F2:F" & lRow)
But the macro is moving all rows that are unique only if every cell in a row is unique from all cells in any other row (I hope that make sense)
Do I misunderstand stand what CriteriaRange means?
Am I misusing Advanced Filter?
Thanks
Code:
Sub Filter()
Dim ws As Excel.Worksheet
Dim r As Range, r1 As Range
Dim lRow As Long
Set ws = ThisWorkbook.Sheets("UnPivot")
lRow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
'Sort on column
Set r1 = ws.Range("F1:F" & lRow)
r1.Sort Key1:=r1, Order1:=xlAscending, Header:=xlYes
'Filter Unique True
Set r = ws.UsedRange
r.AdvancedFilter _
CriteriaRange:=ws.Range("F2:F" & lRow), _
Action:=xlFilterCopy, _
CopyToRange:=ThisWorkbook.Sheets("XXX").Range("A1"), _
unique:=True
End Sub