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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
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

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
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,191,166
Messages
5,985,051
Members
439,935
Latest member
Monty238

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
Top