View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Sort by Cells Interior Color Then by Date

See if this code helps

Sub mysort()


'Move all with .Interior.ColorIndex = 31
'to beginning of worksheet

RowCount = 1
Do While Range("K" & RowCount) < ""
If Range("K" & RowCount).Interior.ColorIndex = 31 Then
If RowCount < 1 Then
Rows(RowCount).Cut
' ActiveSheet.Paste Destination:=Rows(1)
Rows(1).Insert Shift:=xlDown
End If
End If
RowCount = RowCount + 1
Loop

'Now find where end of highlighted cells are located
RowCount = 1
Do While Range("K" & RowCount).Interior.ColorIndex = 31
RowCount = RowCount + 1
Loop
firstNonHighlightedcell = RowCount
LastHighlightcell = RowCount - 1
Lastrow = Range("K" & Rows.Count).End(xlUp).Row

Set sortrange1 = Rows("1" & LastHighlightcell)
Set sortrange2 = Rows(firstNonHighlightedcell & ":" & Lastrow)

sortrange1.Sort _
Key1:=Range("K1"), _
Order1:=xlAscending, _
Key2:=Range("A1"), _
Order2:=xlAscending, _
Header:=xlGuess

sortrange2.Sort _
Key1:=Range("K" & firstNonHighlightedcell), _
Order1:=xlAscending, _
Key2:=Range("A" & firstNonHighlightedcell), _
Order2:=xlAscending, _
Header:=xlGuess

End Sub


"RyanH" wrote:

I have a spreadsheet that I use to keep track of ship dates. Currently if a
particular product is ready to ship I highlight the ship date cell by
changing its interior color = 31. All ship dates are in Column K. Is there
a way to sort the entire worksheet in this order:

1.) all .Interior.ColorIndex = 31 at the top
2.) then sort the dates of those cells in ascending order
3.) then sort all other dates after the .Interior.ColorIndex = 31 by
ascending order
4.) then sort those cells by Sales order number in Column A

Is this possible?