Sort table by color

Dr. Demento

Well-known Member
Joined
Nov 2, 2010
Messages
552
At one point, I had this working, but with all my futzing, I've jacked it up. Can anyone point out why nothing gets sorted?? The colors are the standard yellow, light green, and light blue from the default color palette. I'm at a complete loss; I tried using both .ListColumns and .HeaderRowRange - no errors but no sorting happens either. :banghead:

Thanks y'all.

Code:
[/FONT][/COLOR][/LEFT]Sub demo_filter_byColor()
  filter_byColor ActiveSheet.ListObjects(1), Array(1, 1, 1), Array(1703935, 15773696, 5296274)
End Sub



Sub filter_byColor(lbt As ListObject, _
                   rraCol As Variant, _
                   rraColor As Variant)
'                  rraFontFill As Variant
Const proc_name$ = "filter_byColor"
Dim i As Long, _
    lColor As Long
'  If Not ((UBound(rraCol) - LBound(rraCol)) = (UBound(rraFontFill) - LBound(rraFontFill)) And _
'          (UBound(rraCol) - LBound(rraCol)) = (UBound(rraColor) - LBound(rraColor))) Then _
'    Exit Sub
  
  Application.ScreenUpdating = False
  For i = LBound(rraCol) To UBound(rraCol)
    With lbt.Sort
      .SortFields.Clear
    
'        Select Case rraFontFill(i)
'          Case "Fill"
      .SortFields.Add(lbt.HeaderRowRange(rraCol(i)), xlSortOnCellColor, _
                      xlAscending, , xlSortNormal).SortOnValue.color = rraColor(1)
          
'          Case "Font"
      .SortFields.Add(lbt.ListColumns(rraCol(i)).DataBodyRange, xlSortOnFontColor, _
                           xlAscending, , xlSortNormal).SortOnValue.color = rraColor(i)  'Range(rraCol(i))
        
'        End Select
        
      .Header = xlYes
      .MatchCase = False
      .Orientation = xlTopToBottom
      .SortMethod = xlPinYin
      .Apply
      
    End With 'lbt.Sort
    
  Next i
  
  Application.ScreenUpdating = True
End Sub
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Watch MrExcel Video

Forum statistics

Threads
1,095,971
Messages
5,447,621
Members
405,458
Latest member
newbie111

This Week's Hot Topics

Top