我正在尝试按名称“名称”列按字母顺序对一系列列表进行排序。下面的代码是没有错误的compliling,并且没有错误地运行,但它没有对列表进行排序。
任何人都可以提供帮助吗?
'**
' Sorts the defined list using the definded parameters
''
Function sort_list(list_name As String, column_name As String, Optional sort_order As String = xlAscending)
Dim list As ListObject ' The list that is to be sorted
Dim sort_column As Range ' The column in the list that is to be used as the sort key
' Set the list and the sort column
Set list = WS_ext.ListObjects(list_name)
Set sort_column = list.ListColumns(column_name).Range
' Sort the list
With list.Sort
.SortFields.Clear
.SortFields.Add sort_column, sort_order
.Header = xlYes
.MatchCase = False
.Apply
End With
End Function
答案 0 :(得分:2)
问题是我没有指定哪个参数对于SortFields
函数是哪个。将该行更改为下面修复了我的问题。
.SortFields.Add Key:=sort_column, order:=Sort_order