View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Nick H[_3_] Nick H[_3_] is offline
external usenet poster
 
Posts: 48
Default Sort code not working in 07

Hi Pyrite,

I do a very similar thing in one of my workbooks. When the user clicks
on a header title I call the routine below from within the
SelectionChange event. It works fine in both 03 and 07 versions of
Excel.

Beware wrap-around...


Public Sub DoSort(ByRef rngData As Range, ByRef rngKey As Range,
Optional ByVal Hdr As Long, Optional ByVal Ordr As Long)
' Hdr...
' 0 = xlGuess
' 1 = xlYes
' 2 = xlNo

On Error Resume Next

If Ordr = 0 Then Ordr = 1 'xlAscending by default

rngData.Sort Key1:=rngKey, Order1:=Ordr, Header:=Hdr,
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortTextAsNumbers

End Sub


Assuming that your CommandButton lives in the Worksheet module, you
would call this routine from your CommandButton#_Click routines like
so...

Call DoSort(Me.Range("C9:G407"), Me.Range("C9"))

HTH, Nick H