Hi,
I have a custom sort code, which runs perfectly when I am calling it from a module, but when I copy it inside the my codes in the sheet, and address it, it returns error.
Can somebody help and explain?
here is my code:
I have a custom sort code, which runs perfectly when I am calling it from a module, but when I copy it inside the my codes in the sheet, and address it, it returns error.
Can somebody help and explain?
here is my code:
Code:
Sub custom_sort()
Application.calculation = xlManual
Application.EnableEvents = False
Application.ScreenUpdating = False
Call identification
Dim Customlist(250) As String
Dim ii As Double, c As Range
ii = 0
For Each c In Selection
If Not c.Rows.Hidden Then
Customlist(ii) = c
Debug.Print "ii = "; ii & " " & Customlist(ii)
ii = ii + 1
Else
End If
Next
Application.AddCustomList ListArray:=Customlist
tb.Sort.SortFields.Clear
tb.Sort.SortFields.Add Key _
:=Range("tbl[Work Book]"), SortOn:=xlSortOnValues, Order:=xlAscending, _
CustomOrder:=Application.CustomListCount, DataOption:=xlSortNormal
ws.Activate
With tb.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Application.DeleteCustomList Application.CustomListCount
Application.calculation = xlCalculationAutomatic
Application.EnableEvents = True
End Sub