View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Defining Sort Order in Excel Template

I think I would put a dedicated macro that sorted exactly the way I wanted.
Then I'd drop a button from the Forms toolbar on that worksheet--and assign the
macro to that button.

Then the users can still sort by whatever they want (via Data|Sort).

Option Explicit
Sub mySpecialSort()

Dim myRng As Range

With ActiveSheet
Set myRng = .Range("A5:X" & .Cells(.Rows.Count, "A").End(xlUp).Row)
End With

With myRng
.Cells.Sort key1:=.Columns(1), order1:=xlAscending, _
key2:=.Columns(2), order2:=xlAscending, _
key3:=.Columns(6), order3:=xlAscending, _
header:=xlYes
End With

End Sub


I sorted columns A:X--change that if you need to. And I assumed that row 5 had
headers. Change xlyes to xlno if it doesn't.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Yogi Watcher wrote:

I am creating Excel Template. Template has first 4 rows reserved for report
header. I would like to sort rest of the report to be sorted on Column-A,
then on Column-Bm and then on Column-F.

How do I define that sort order in template itself so that any time when
somebody generates report and opens that with this template it is
automatically sorted based on the order defined in template.


--

Dave Peterson