Sorting Macro in Excel 2007

K

Kevin K

Is there a way to create a sorting macro in Excel 2007 that would allow me to
use it for any workbook and any section of a worksheet? For instance, I
would need the macro to work specifically on the rows I highlight only. I
would also need to set up the macro to sort based on 2 or 3 column letters (I
would just change this in the VBA code for any new workbooks that aren't
lined up the same).

Thanks for your idea. This would save me so much time.
Kevin
 
B

Bernie Deitrick

Kevin,

The example below will sort the selected range based on the third column of the selection ascending,
and the first column of the selection descending.

You can modify it easily; I hope you see the pattern so that you can get it to work in your required
situation.

HTH,
Bernie
MS Excel MVP

Sub KevinSortMacro()
Col1 = 3
Col2 = 1
Selection.Sort Key1:=Selection.Cells(1, Col1), Order1:=xlAscending, _
Key2:=Selection.Cells(1, Col2), Order2:=xlDescending, _
Header:=xlYes
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top