Sort selection

dutchninja

New Member
Joined
Aug 5, 2011
Messages
2
Good morning,

I'm looking for the code for sorting a selection. (in excel 2010)
This selection can be different anytime and I want to sort on columns R, E and F (asc, asc, asc)

So, I select rows 1 till 10 and sort them.
Next day, I add a row, so rows 1 till 11 needs to be sorted. or row 345 till 456, etc.

I want to add this code to a button because when using the standard Excel button, everytime I have to fill in the columns manually.

Anyone knows?

Thanks !
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
For instance:

Code:
Sub f()
    With Selection
        .Sort Range("R" & .Row), , Range("E" & .Row), , , Range("F" & .Row), Header:=xlNo
    End With
End Sub
 
Upvote 0
Wigi,

I have been needing something like this for a long time. You just solved my issue as well. Thank you.
 
Upvote 0
The code was working great until I changed a couple of columns around and ran the same code with a different selection i.e. Column C first, Column D second and Column E third but now the sort is including the header row along with the sort and moving it from the header. Any idea of what I am doing wrong...

Sub Sort_Quotes()
With Selection
.Sort Range("C" & .Row), , Range("D" & .Row), , , Range("E" & .Row), Header:=xlNo
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,487
Members
452,917
Latest member
MrsMSalt

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