嘿伙计我继续得到运行时错误1004对象'_Global'的方法'范围'当我尝试进行这种简单的排序时失败。
Sub Assy_Weld_TrumpfSort()
'
' Assy_Weld_TrumpfSort
'
Dim sh As Worksheet
Dim TableName As String
Dim theTable As ListObject
Set sh = ActiveSheet
TableName = sh.Name
Set theTable = ActiveWorkbook.Worksheets(TableName).ListObjects(TableName)
theTable.sort.SortFields.Clear
theTable.sort.SortFields.Add _
Key:=Range(TableName & "[PART NUMBER]"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
With theTable.sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
答案 0 :(得分:0)
由于
,您将收到该错误 Range(TableName & "[PART NUMBER]")
尝试将其更改为以下范围:
ActiveWorkbook.Worksheets(TableName).Range("A1")
将使用“A”列作为第一个排序键进行排序。