Sort table by color

Dr. Demento

Well-known Member
Joined
Nov 2, 2010
Messages
618
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
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
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,223,891
Messages
6,175,229
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top