I am trying to get this code I found online to work for my need and cant figure out how to combine it. The first bit Sort_Selection works great to sort by value, but I need to sort by font color of selected range. This code is really terrific in that its not specific to a sheet name and such and someone like me can just put it into any sheet and change the column number so Id like to keep it that way. I recorded a macro and tried swapping out the sort info but I keep getting errors every way I can come up with to combine them. Does anyone know how to combine these so I can get it to sort selection by font colors? Thanks
Code:
Public Sub SortSelection()
'use the keyword "Selection" for the currently selected range
With ActiveSheet.Sort
.SortFields.Clear
'the key you want to use is the column to sort on. I used column 1, which is "A", column "B" is 2, etc
.SortFields.Add Key:=Selection.Columns(3), Order:=xlDescending
.SetRange Selection
.Apply
End With
End Sub
Code:
Sub Macro26()
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add(Range("C19670:C19727"), _
xlSortOnFontColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(51, 102 _
, 255)
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add(Range("C19670:C19727"), _
xlSortOnFontColor, xlDescending, , xlSortNormal).SortOnValue.Color = RGB(0, 0, _
0)
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A19670:AM19727")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Last edited: