我在最新版本的 Mac 版 Excel 上遇到了这个问题。
这是宏:
Sub Run()
'
' Run Macro
'
'
Sheets("Data").Select
Cells.Select
Range("BK1").Activate
Selection.Replace What:="unknown", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets("Pivot Table").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
ActiveSheet.PivotTables("PivotTable3").PivotCache.Refresh
ActiveSheet.PivotTables("PivotTable4").PivotCache.Refresh
Sheets("Formatted Data").Select
ActiveWorkbook.Worksheets("Formatted Data").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Formatted Data").AutoFilter.Sort.SortFields.Add Key _
:=Range("A4"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Formatted Data").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
当我运行它时,我收到 MSFT Visual Basic 错误:
Run-time error '1004':
Application-defined or object-defined error
如果我删除这部分,它可以运行良好,但就最终结果而言并不是我所需要的:
Sheets("Data").Select
Cells.Select
Range("BK1").Activate
Selection.Replace What:="unknown", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
更新
如果我只删除这小部分,宏就会运行,但不确定删除它是否会丢失任何东西:
SearchFormat:=False, _
ReplaceFormat:=False