Sorting & Filtering Table Columns by Color-To be applicable for any selected column

excelakos

Board Regular
Joined
Jan 22, 2014
Messages
79
Hi there

Below is the macro recorded as an example of the task, which is to first sort column by color and then filter column by color.

I want to keep elements about what sheet I am on, which table etc, but how could I change the specific range [(Range("t_coupon[[#All],[1/2]]")] and [Field:=32] in this example and make the code "global" for each column I manually select each time??

Thank you in advance Experts!!!!

VBA Code:
Sub m_sort_n_filter_by_color()
'
' m_sort_n_filter_by_color Macro
'

'
    ActiveWorkbook.Worksheets("Coupon").ListObjects("t_coupon").Sort.SortFields. _
        Clear
    ActiveWorkbook.Worksheets("Coupon").ListObjects("t_coupon").Sort.SortFields.Add _
        (Range("t_coupon[[#All],[1/2]]"), xlSortOnCellColor, xlAscending, , _
        xlSortNormal).SortOnValue.Color = RGB(255, 192, 0)
    With ActiveWorkbook.Worksheets("Coupon").ListObjects("t_coupon").Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    ActiveSheet.ListObjects("t_coupon").Range.AutoFilter Field:=32, Criteria1:= _
        RGB(255, 192, 0), Operator:=xlFilterCellColor
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,215,079
Messages
6,123,009
Members
449,093
Latest member
ikke

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