Sorting Macro in Excel 2007
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
"Kevin K" wrote in message
...
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
|