Hi, can anyone help with Application Custom List to Sort Data
I have a command button on sht2 with the following code to sort data on sht4 but excel will not save and crashes after running the macro. I have tried tinkering around a little with the code but keep getting errors.
For example I have tried changing the +2 to +6 in the code as there is 5 Default Custom Lists already exiting within excel and this allowed me to save after running the code but did not sort on sht4 the way it should?
Any help would be appreciated
Regards
pwill
I have a command button on sht2 with the following code to sort data on sht4 but excel will not save and crashes after running the macro. I have tried tinkering around a little with the code but keep getting errors.
For example I have tried changing the +2 to +6 in the code as there is 5 Default Custom Lists already exiting within excel and this allowed me to save after running the code but did not sort on sht4 the way it should?
Any help would be appreciated
Code:
Private Sub CommandButton110_Click()
Dim Sht2 As Worksheet: Set Sht2 = Sheet02
Dim Sht4 As Worksheet: Set Sht4 = Sheet04
Dim ListNum As Long
Dim lRowA As Long
Dim lRowM As Long
Application.ScreenUpdating = False
lRowA = Sht4.Cells(Rows.Count, "A").End(xlUp).Row
lRowM = Sht4.Cells(Rows.Count, "M").End(xlUp).Row
Sht4.Range("A2:A" & lRowA) = _
Sht4.Range("E2:E" & lRowA).Value
Sht4.Range("M2:M" & lRowM) = _
Sht4.Range("Q2:Q" & lRowM).Value
ListNum = Application.CustomListCount + 2
Application.AddCustomList Array("0", "1", "-1", "2", "-2", "3", "-3", "4", "-4", "5", "-5", "6", "-6", "7", "-7", "8", "-8", "9", "-9", "10", "-10", "11", "-11", "12", "-12", "13", "-13", "14", "-14", "15", "-15", "16", "-16", "17", "-17", "18", "-18", "19", "-19", "20", "-20", "21", "-21", "22", "-22", "23", "-23", "24", "-24", "25", "-25", "26", "-26", "27", "-27", "28", "-28", "29", "-29", "30", "-30", "31", "-31", "32", "-32", "33", "-33", "34", "-34", "35", "-35", "36", "-36", "37", "-37", "38", "-38", "39", "-39", "40", "-40", "41", "-41", "42", "-42", "43", "-43", "44", "-44", "45", "-45", "46", "-46", "47", "-47", "48", "-48", "49", "-49", "50", "-50", "51", "-51", "52", "-52", "53", "-53", "54", "-54", "55", "-55", "56", "-56", "57", "-57", "58", "-58", "59", "-59", "60")
With Sht4
.Range("A2:K" & lRowA).Sort Key1:=.Range("E2"), order1:=xlAscending, _
Header:=xlNo, OrderCustom:=ListNum
.Range("M2:W" & lRowM).Sort Key1:=.Range("Q2"), order1:=xlAscending, _
Header:=xlNo, OrderCustom:=ListNum
End With
ListNum = ListNum - 1
Application.DeleteCustomList ListNum
Application.ScreenUpdating = True
End Sub
Regards
pwill
Last edited: