VBA to sort

g48dd

Board Regular
Joined
Jan 12, 2009
Messages
101
Excel 2003: I have this from the macro recorder:

Code:
    Range("O10:W25").Select
    Selection.Sort Key1:=Range("P11"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal

Is there a better way to get the same thing done? Header row is on O10 but it's not necessary to include it, I do need it ascending, I will sort columns P,Q,R,S,T,U,V, & W. What I am doing is sorting the range O10:W25 but I sort it by column P then I copy column O10:O20 and paste it the next sheet (sheet 7) cell I10, then go back and get Column P10:P20 & paste that in Sheet 7 J10, then go back and sort the whole range O10:W25 again but this time by column Q, then copy O10:O20 and paste it to sheet 7 cell L10; go back and get Q10:Q20 paste that to M10 ect.. I can do the back and forth stuff with
Code:
[O10:O20].Copy Destination:=Sheets(ActiveSheet.Index +1).[I10]

and I can just copy what the macro recorder has done but usually there is a better way and that is why I am asking. I know it looks silly but this is just a sample in reality I am working with 200 rows and taking the bottom 10, that is why it is sorted ascending, and I always have to have Column O with what ever column I am sorting as column O is the name.

Thank you
Ken
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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