0

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

1 回答 1

0

You will be getting that error because of

 Range(TableName & "[PART NUMBER]")

Try changing it to range like:

ActiveWorkbook.Worksheets(TableName).Range("A1")

That will sort using column "A" as the first sort key.

于 2013-10-31T17:03:16.587 回答