VBA Code - Sort by Custom List Reference

Status
Not open for further replies.

tlc53

Active Member
Hi there,

I am trying to sort my data which is located under headings A52:K52 by the account number order, as stipulated in cells K21:K35.

This is my attempt but it is possible I'm way off the mark. Can anyone see how I can get this working please?

I don't want to refer to a particular sheet, it just needs to run on the active sheet.

Thank you!!

Code:
Sub CustomSort()


    Selection.CurrentRegion.Select
    Application.AddCustomList Selection:=Range("K21:K35")
    Sort.SortFields.Clear
    Sort.SortFields.Add2 Key:=Range("K53:K100000"), SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
        Range("K21:K35"), DataOption:=xlSortNormal
    Sort.ActiveSheet
        .SetRange Range("A52:K100000")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply


End Sub
 

James006

Well-known Member
Hi,

Since you have added your Custom List to all available lists ... you could test following modification:

Code:
CustomOrder:=Application.CustomListCount + 1
Hope this will help
 
Status
Not open for further replies.

Some videos you may like

This Week's Hot Topics

Top