Custom sort issue

ricorico

New Member
Joined
Jun 15, 2013
Messages
14
Here is my code :

Sub SortCol()

With Application
.AddCustomList listArray:=Array("P9:P16")
x = .CustomListCount
Range("A9:N16").Sort Key1:=Range("A9"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=x, MatchCase:=False, Orientation:=xlTopToBottom
.DeleteCustomList ListNum:=x + 1
End With
End Sub

Cell range A9:N16 are the data to be sorted. P9:P16 is a custom list containing number (i.e. 1 ,2 ,3 ,5 ,7 ,9 ,8 ,6).
The code doesn't work , any idea?


from KH
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
You're welcome
I use this code work fine.

Sub SortCol()

With Application
.AddCustomList ListArray:=Array("3", "4", "6", "7", "8", "2", "1", "5", """""")
x = .CustomListCount
Range("A9:N16").Sort Key1:=Range("A9"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=x, MatchCase:=False, Orientation:=xlSortColumns
.DeleteCustomList ListNum:=x + 1
End With

End Sub


But don't know how to change " Array("3", "4", "6", "7", "8", "2", "1", "5", """""")" to a range (P9:P16)
 
Upvote 0
Try this method to create the custom list
- it works for me but unfortunately for you I am not a Mac user either :unsure:
VBA Code:
    Dim m As String, c As Range
    With Application
        For Each c In Range("P9:P16")
            m = m & c & ", "
        Next c
        m = Left(m, Len(m) - 2)
        .AddCustomList ListArray:=Array(m)
    End With
 
Upvote 0
Try this method to create the custom list
- it works for me but unfortunately for you I am not a Mac user either :unsure:
VBA Code:
    Dim m As String, c As Range
    With Application
        For Each c In Range("P9:P16")
            m = m & c & ", "
        Next c
        m = Left(m, Len(m) - 2)
        .AddCustomList ListArray:=Array(m)
    End With
Thx for your reply, I finally got it to work by modify my original code.

I will try your code too , Thx!
 
Upvote 0

Forum statistics

Threads
1,225,360
Messages
6,184,508
Members
453,237
Latest member
lordleo

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