嘿伙计们,当我尝试执行此简单排序时,我不断收到运行时错误 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