I am trying to put together a macro which will run an Advance filter and
bring back unique records. I need it to work on an range which may increase
or decrease. the code below works sometimes but depends I think what cell is
active when the macro is run.

Sub Test()
Dim Irange As Range
Dim ORange As Range
FinalRow = Cells(65536, 1).End(xlUp).Row
NextCol = Cells(1, 255).End(xlToLeft).Column + 2
Range(Selection, Selection.End(xlToRight)).Copy Destination:=Cells(1, NextCol)
Set ORange = Cells(1, NextCol)
Set Irange = Range("a1").Resize(FinalRow, NextCol - 2)
Irange.AdvancedFilter Action:=xlFilterCopy, copytorange:=ORange, Unique:=True
End Sub

Any ideas? Thank you for your help.

Esther