Will someone please help me with this? I have been trying for a couple weeks on and off and I keep giving up out of frustration. I am trying to sort by column T, by cells colors for the rows I have selected which changes. I recorded a macro and tried applying solutions from similar questions Ive read while looking for a solution. I know this has been asked many times, but I just cant get it to work for my criteria. This is the recorded macro with the sorting criteria I need followed by the closest solution/explanation I have found.
Code:
Sub Sort_Selection()
ActiveWorkbook.Worksheets("Live").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Live").Sort.SortFields.Add(Range("T419:T452"), _
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(79, 129 _
, 189)
ActiveWorkbook.Worksheets("Live").Sort.SortFields.Add(Range("T419:T452"), _
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(153, _
255, 204)
ActiveWorkbook.Worksheets("Live").Sort.SortFields.Add(Range("T419:T452"), _
xlSortOnCellColor, xlDescending, , xlSortNormal).SortOnValue.Color = RGB(153, 0 _
, 204)
ActiveWorkbook.Worksheets("Live").Sort.SortFields.Add(Range("T419:T452"), _
xlSortOnCellColor, xlDescending, , xlSortNormal).SortOnValue.Color = RGB(0, 255 _
, 0)
With ActiveWorkbook.Worksheets("Live").Sort
.SetRange Range("A419:AE452")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Code:
Public Sub sSortSelection()
'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(1), Order:=xlDescending
.SetRange Selection
.Apply
End With
End Sub