View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
DOR
 
Posts: n/a
Default Is there a "rank" like feature for alpha?

Record a simple Sort macro and then attach it to a button on your
worksheet or put it in the Worksheet module, with the name

Private Sub WorkSheet_Deactivate()

...sort statements

End Sub

That will cause the macro to be run every time you deactivate the
sheet. However, you have to be careful to deactivate events and
reactivate within the macro. The following macro has worked for me to
sort a sheet called Results, but I don't claim any great VBA skills so
don't take it as being the best practice!

Private Sub WorkSheet_Deactivate()
'Sort the entered results whenever the Results sheet is deactivated
Dim strMySht As String
strMySht = ActiveSheet.Name
Application.ScreenUpdating = False
Worksheets("Results").Select
Range("A1").CurrentRegion.Select
Selection.Sort _
Key1:=Range("EntryDate"), Order1:=xlAscending, _
Key2:=Range("HomeTeam"), Order2:=xlAscending, _
Header:=True
Range("A1").Select
Application.EnableEvents = False
Worksheets(strMySht).Activate
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

You will need to substitute your own range names for the sort columns.
- substitute a reference in the Surname column for Entry Date and a
reference in the First Name column for Home Team, and substitute the
name of your entry sheet for Results

I may not have chosen the best way to deal with deactivating events
because if you get a failure in the next statement, events will stay
deactivated and you will need to run the macro explicitly again (press
F5), after correcting it, or restart Excel.

You may choose to run this automatically when the workbook is open or
closed instead by putting it in the Workbook VBA module.

Or you could do it the hard way by generating a sorting number from
each name using base 27 arithmetic (26 alpha plus space, ignoring
apostrophes et al, a=1, b=2, c=3 etc.) and rank based on those numbers.
You need not use all the letters of each name, the first 3 or 4 would
be enough to get close enough to alpha, but note that in using RANK for
sorting you will need to deal with ties. There are many threads on
these forums dealing with methods for doing that, if your eally want
toi use base 27 arithmetic to get quasi-alphabetic sequence.

HTH

Declan O'R