Sorting Macro in Excel 2007

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
If you're just selecting different sets of data each time you sort, you might as well use the shortcut for sorting on the toolbar. Even if you wrote a module and created a macro button on the tool bar specifying parameters of the set, it would still take the same amount of time I think. Doesn't the original sort command give you the options you need? It offers multiple sort criteria....

Of course, I am still using Office 2003, but things aren't that much different with 2007 programs are they? Except for the interface I hear....
 
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
 
Back
Top