lostyankee
New Member
- Joined
- Jul 14, 2019
- Messages
- 7
I have a spreadsheet that I need to sort that has multiple colors, sorting:
Blue
Red
Orange
Yellow
After this I have code to remove duplicates in the data, but I need to retain these in priority order, hence the need for sorting. Any ideas?
Blue
Red
Orange
Yellow
After this I have code to remove duplicates in the data, but I need to retain these in priority order, hence the need for sorting. Any ideas?
VBA Code:
Sub SortByColor()
ActiveWorkbook.Worksheets("IYD All").Sort.SortFields.Clear
' Sort column B by Blue Priority
ActiveWorkbook.Worksheets("IYD All").Sort.SortFields.Add(Range("b2"), _
xlSortOnCellColor, xlAscending, , _
xlSortNormal).SortOnValue.Color = RGB(0, 204, 255)
' Sort Column B by Red Priority
ActiveWorkbook.Worksheets("IYD All").Sort.SortFields.Add(Range("b2"), _
xlSortOnCellColor, xlAscending, , _
xlSortNormal).SortOnValue.Color = RGB(255, 0, 0)
' Sort column B by Orange Priority
ActiveWorkbook.Worksheets("IYD All").Sort.SortFields.Add(Range("b2"), _
xlSortOnCellColor, xlAscending, , _
xlSortNormal).SortOnValue.Color = RGB(255, 120, 0)
' Sort column B by Yellow Priority
ActiveWorkbook.Worksheets("IYD All").Sort.SortFields.Add(Range("b2"), _
xlSortOnCellColor, xlAscending, , _
xlSortNormal).SortOnValue.Color = RGB(255, 255, 0)
End Sub