Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
lock cells based on interior color MIke Excel Discussion (Misc queries) 4 December 27th 07 08:59 PM
Cell background color (interior color) setting not working Martin E. Excel Programming 1 May 21st 06 07:00 PM
cells interior/color index tandavina[_7_] Excel Programming 4 February 12th 06 11:28 AM
Sum all cells with interior color... Ctech[_65_] Excel Programming 4 January 11th 06 07:46 PM
Passing Back Color to Interior Color ExcelMonkey[_190_] Excel Programming 1 March 22nd 05 04:27 PM


All times are GMT +1. The time now is 03:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"