View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Help with sorting lists of data.

I thought we solved this problem at the beginning of July. Try this code.
The blanks should sort to the botoom of the table since we are sorting the
times descending. If not, I wrote a 2nd macro that puts N/A in the blank
cells to force them to the end. This si the same solution you eventually
worked out.


Sub SortTable1()

LastRow = Range("H" & Rows.Count).End(xlUp).Row
Col_J = 9
Col_M = 13

For ColCount = Col_J To Col_M
Set Key2 = Cells(5, ColCount)
Rows("5:" & LastRow).Sort _
key1:=Range("I5"), _
order1:=xlDescending, _
Key2:=Key2, _
order2:=xlAscending

Next ColCount

End Sub

Sub SortTable2()

LastRow = Range("H" & Rows.Count).End(xlUp).Row
Col_J = 9
Col_M = 13

'fill in empty cells in table
For RowCount = 5 To LastRow
For ColCount = Col_J To Col_M
If Cells(RowCount, ColCount) = "" Then
Cells(RowCount, ColCount) = "N/A"
End If
Next ColCount
Next RowCount

For ColCount = Col_J To Col_M
Set Key2 = Cells(5, ColCount)
Rows("5:" & LastRow).Sort _
key1:=Range("I5"), _
order1:=xlDescending, _
Key2:=Key2, _
order2:=xlAscending

Next ColCount

End Sub


"NDBC" wrote:

I need to sort the following list of lap times so that all the riders who
have come in after the 2:00:00 mark are sorted in terms of number of laps
then finishing time. Then the remaining riders who have pulled out before the
2:00:00 mark need to be sorted the same way. Based on the example below the
list of rider numbers should end up in the order 405, 411, 401 402 and 409. I
have included the cell references as well just in case they are required. I
need to do it using vb code so that I can run it from a command buttonl.

Thank you for any suggestions.

H I J K L
M

Rider Laps Lap1 lap2 lap3 lap4
No.

5 401 4 0:37:49 1:09:48 1:43:27 1:58:48
6 405 4 0:38:49 1:11:20 1:42:57 2:16:14
7 402 3 0:40:36 1:17:04 1:59:38
8 411 3 0:44:03 1:21:27 2:04:01
9 409 2 0:38:38 1:10:47