下面的宏是我记录的自定义排序。我用变量替换了实际的表名,所以我可以为任何其他表名运行它。我不希望它特定于一个名字。当我运行宏时,我得到:
运行时错误“1004”:未找到具有指定名称的项目
当我单击帮助按钮时,它会将我发送到 Excel 帮助菜单。你们能告诉我我错过了什么吗?如果可能的话,有没有办法缩短我的代码。我知道录音可能很长。
**注意所有这些都在一个表中
Dim sh As Worksheet
Dim TableName As String
Set sh = ActiveSheet
TableName = sh.Name
ActiveWorkbook.Worksheets(TableName).ListObjects(TableName).sort. _
SortFields.Clear
ActiveWorkbook.Worksheets(TableName).ListObjects(TableName).sort. _
SortFields.Add Key:=Range(TableName, [BEVEL]), SortOn:=xlSortOnValues,
Order:=xlAscending, _
CustomOrder:="BEVEL_YES_MITER,BEVEL_NO_RADIUS", DataOption:=xlSortNormal _
ActiveWorkbook.Worksheets(TableName).ListObjects("TableName").sort. _
SortFields.Add Key:=Range(TableName, [MATERIAL]), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets(TableName).ListObjects(TableName).sort. _
SortFields.Add Key:=Range(TableName, [Length]), SortOn:=xlSortOnValues, _
Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets(TableName).ListObjects(TableName).sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Selection.AutoFilter
End Sub