student214
student214

Reputation: 85

Excel macro that executes a multi-level custom sort using a custom list for ordering

I am trying to create a macro that executes a two-level sort using a custom list for a dynamic table.

The table is updated on a daily basis and, therefore, requires the macro to capture a varying number of rows.

The Custom List that I would like to order the Location column by is: "Greater London, Liverpool, Birmingham, Manchester, Sheffield, Leeds, Bristol" - (in reality my custom list is rather long and consists of various strings).

The below is what I have written so far and would appreciate any input. Thanks!

Sub CustomSort()

Range("B2").CurrentRegion.Sort _ 
key1:= Range("C2"), Order1:=xlAscending, Orientation:=xlTopToBottom, Header:=xlYes, _
key2:= Range("D2"), Order1:=xlAscending, Orientation:=xlTopToBottom, Header:=xlYes, CustomOrder:= _
"Greater London,Liverpool,Birmingham,Manchester,Sheffield,Leeds,Bristol"

End Sub

enter image description here

Upvotes: 0

Views: 533

Answers (0)

Related Questions