【发布时间】:2014-09-25 21:40:39
【问题描述】:
我在 VBA 中使用排序时遇到问题。我看到了这个答案对我不起作用的帖子:Sort in VBA
我相信您可以对最多 nr 个记录进行排序。那是对的吗?我想对具有 188,000 条记录的工作表/表格中的 4 个条件进行排序。
我总是在.Apply 语句中遇到错误:"run-time error '1004': application-defined or object-defined error"
在我的代码下面:
Sub Sort_Table()
Dim sht As Worksheet
Set sht = ActiveWorkbook.Worksheets("Sheet1")
sht.Activate
With sht.ListObjects("Table1").Sort
.SortFields.Clear
.SortFields.Add Key:=Range("Table1[Date]"), SortOn:=xlSortOnValues, Order:=xlAscending ', DataOption:=xlSortNormal
.SortFields.Add Key:=Range("Table1[Country Code]"), SortOn:=xlSortOnValues, Order:=xlAscending ', DataOption:=xlSortNormal
.SortFields.Add Key:=Range("Table1[Rating]"), SortOn:=xlSortOnValues, Order:=xlAscending ', DataOption:=xlSortNormal
.SortFields.Add Key:=Range("Table1[Segment]"), SortOn:=xlSortOnValues, Order:=xlAscending ', DataOption:=xlSortNormal
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
【问题讨论】: