I have tried the following code to sort column B starting in B7 and the sort I desire based on 5 colors
Code: Select all
Sub Test()
With Worksheets("Sheet1").Sort
.SortFields.Clear
.SortFields.Add(Range("B7"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(0, 176, 240)
.SortFields.Add(Range("B7"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, 255, 255)
.SortFields.Add(Range("B7"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, 255, 0)
.SortFields.Add(Range("B7"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(252, 213, 180)
.SortFields.Add(Range("B7"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, 192, 0)
.SetRange Range("A7:G" & Cells(Rows.Count, "B").End(xlUp).Row)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub