Excel Tables sorting depending on Cell value

imothep77

New Member
Joined
Aug 9, 2013
Messages
5
Hi all, I hope someone can help with this tricky one.

My Excel Table "Tracker" is sorted using the values in column "Index", I have a column named "Status" which can have several values, one of them being "Cancelled".
I want to sort my table so that the rows where the status is "Cancelled" are moved to the end of the table and sorted by "Index".

Also, I would like the row move to take place automatically upon changing the "Status" using the Worksheet_Change procedure, i.e when I change the Status to "Cancelled", say on row D where "Index" is 11, I want this row to be sent to the end of the table with all the "Cancelled" rows between rows with index 10 and 15 (which are currently "Cancelled" and contiguous). Likewise, when the status changes from "Cancelled" to any other value, I want the order sent back with the other orders in the Table at the right place (sorted by index)

Thanks in advance for your help.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
hi All,

Replying to myself in case this can be of use to anyone else:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)


Dim tbl As ListObject
Dim tRngSelect As Range
Dim lngListRow As Long


    If Intersect(Target, Range("All_Details[Customer Status]")) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub
    
    Set tbl = ListObjects("All_Details")
    
    Application.EnableEvents = False
    
        With tbl.Sort
            .SortFields.Clear
            .SortFields.Add Key:=tbl.ListColumns("Customer Status").Range, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
            .SortFields.Add Key:=tbl.ListColumns("Index").Range, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
            .Header = xlYes
            .Apply
        End With
        
    Application.EnableEvents = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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