2

我试图通过名为“名称”的列按字母顺序对一系列列表进行排序。下面的代码编译没有错误,运行没有错误,但它没有对列表进行排序。

任何人都可以提供帮助吗?

'**
 ' 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
4

1 回答 1

2

问题是我没有指定函数的哪些参数SortFields。将该行更改为以下内容解决了我的问题。

.SortFields.Add Key:=sort_column, order:=Sort_order
于 2012-11-08T14:57:00.040 回答