CopyToRange with sort

David0079

New Member
Joined
Jul 26, 2007
Messages
44
Does anyone have any idea whats going wrong here? Have I got the syntax wrong somewhere?

Code:
        Sheets("Data").Columns("E:E").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("FA1"), Unique:=True
        
        Columns("FA1:FA").Select
        Selection.Sort Key1:=Range("FA:FA)
        Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
        Application.Goto Reference:="R1C1"
        
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I think it's in this line

Columns("FA1:FA").Select

If you specify a row on either side of the : , you must specify a row on BOTH sides...

Try

Code:
                Sheets("Data").Columns("E:E").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("FA1"), Unique:=True
        
        Range("FA:FA").Sort Key1:=Range("FA:FA"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
        Application.Goto Reference:="R1C1"
        
End Sub
 
Upvote 0
If the DESTINATION Range of the Unique Filter is already occupied, it will error.

Maybe you need to add a clear contents of that range first...
also, is this all happening on 1 sheet ("data"). You may need to qualify the sheet name in all the range/column refs...

This works for me....

Code:
Sheets("Data").Range("FA:FA").ClearContents
Sheets("Data").Columns("E:E").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheets("Data").Range("FA1"), Unique:=True
        
Sheets("Data").Range("FA:FA").Sort Key1:=Sheets("Data").Range("FA:FA"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Application.Goto Reference:="R1C1"
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,019
Members
448,938
Latest member
Aaliya13

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top