Sorting with VB

Tren2k

New Member
Joined
Jan 25, 2008
Messages
14
Hi Guys

Can someone tell me how to amend the following line of code to sort by column D then by column E, ive tried variations like "sort 4 & 5" etc but cant seem to crack it

.Range("A2:AA" & iRow).Sort 4, xlAscending, xlNo

Thanks
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Code generated by macro recorder gives you:
Range("A2:AA" & iRow).Sort Key1:=Range("D1"), Order1:=xlAscending, Key2:=Range("E1"), Order2:=xlAscending
 
Upvote 0
Have you tried recording a macro while doing it manually? The syntax for the Sort method is:

Sort(Key1, Order1, Key2, Type, Order2, Key3, Order3, Header, OrderCustom, MatchCase, Orientation, SortMethod, DataOption1, DataOption2, DataOption3)
 
Upvote 0
Thanks for the reply, I'm using a built in spreadsheet control and this method doesn't work with it.
 
Upvote 0
Thanks for the reply, I'm using a built in spreadsheet control and this method doesn't work with it.

Why didn't you mention that at the outset? The syntax for the Spreadsheet Control's Sort method is:

Sort(ColumnKey, Order, Header)

which you already have. It doesn't cater for sorting by more than one column.
 
Upvote 0
Why didn't you mention that at the outset? The syntax for the Spreadsheet Control's Sort method is:

Sort(ColumnKey, Order, Header)

which you already have. It doesn't cater for sorting by more than one column.

Sorry was in the middle of it and it skipped my mind, thanks for letting me know Andrew.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,710
Members
452,939
Latest member
WCrawford

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