I've tried a number of methods to filter a column for unique values (including blanks and blanks with a space inside). I want to filter these values and then paste them into column a in another sheet.
Sub filter_2()
With Sheets("ICM flags")
.Columns("a").AdvancedFilter Action:=xlFilterCopy, copytorange:=Sheets("Flag Update (2)").Range("a2"), Unique:=True
End With
End Sub
The method above works for .range("a2")
but if I try to use .range("a1")
I get runtime error 1004 advanced filter method of class failed.
I get runtime error 1004 advanced filter method of class failed with the method below.
Sub unique_filter()
Sheets("ICM flags").Columns("a").AdvancedFilter _
Action:=xlFilterCopy, _
copytorange:=Sheets("Flag Update (2)").Range("a1"), Unique:=True
End Sub
For both of the above methods and with the edits to Davesexcel answer:
Sub AdvFilter()
Dim ws As Worksheet, sh As Worksheet
Dim rng As Range, Frng As Range
Set sh = Sheets("ICM Flags")
Set Frng = sh.Range("A:A")
Set ws = Sheets("Flag Update (2)")
Set rng = ws.Range("A1")
'Frng.AdvancedFilter Action:=xlFilterCopy, copytorange:=rng, Unique:=True
Frng.AdvancedFilter Action:=xlFilterInPlace, Unique:=True
End Sub
The method works for FilterInPlace
but not CopyToRange