目前我正在尝试创建一个自动过滤某些特定范围的过程。 一切正常,直到引擎进入“。apply”的步骤,然后所有崩溃,我得到非常受欢迎的异常“1004”。有人可以来吗?
Sub EFilter(Src As String, Tgt As String, BRT As String, BRS As String, Tab1 As String, Tab2 As String)
FRange = "E4"
Workbooks(Src).Sheets(Tab1).Activate
Columns("E:F").Select
Selection.Delete Shift:=xlToLeft
Range("G5").Select
ActiveCell.FormulaR1C1 = "=RC[-4]+RC[-2]"
Range("G5").Select
Selection.AutoFill Destination:=Range("G5:H5"), Type:=xlFillDefault
Range("G5:H5").Select
Selection.AutoFill Destination:=Range("G5", Range("a4").End(xlDown).Offset(0, 7)), Type:=xlFillDefault
Range("G5", Range("a4").End(xlDown).Offset(0, 7)).Select
ActiveSheet.Calculate
Range("G5").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Range("C5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("F5").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=ABS(RC[-2])"
Range("F5").Select
Selection.AutoFill Destination:=Range("F5", Range("a4").End(xlDown).Offset(0, 5)), Type:=xlFillDefault
Range("F5", Range("a4").End(xlDown).Offset(0, 5)).Select
ActiveSheet.Calculate
Range("E5").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=(RC[-1]-RC[-2])"
Range("E5").Select
Selection.AutoFill Destination:=Range("E5", Range("a4").End(xlDown).Offset(0, 4)), Type:=xlFillDefault
Range("e5", Range("a4").End(xlDown).Offset(0, 4)).Select
ActiveSheet.Calculate
Range(FRange).Value = "Change"
' Range("A4:F4").Select
' Range(Selection, Selection.End(xlToRight)).Select
' Range(Selection, Selection.End(xlDown)).Select
'Selection.AutoFilter
Range(BRS, Range(BRS, Range(BRS).End(xlDown))).AutoFilter
Application.CutCopyMode = False
ActiveWorkbook.Worksheets(Tab1).AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets(Tab1).AutoFilter.Sort.SortFields.Add _
Key:=Range("F5", Range("a4").End(xlDown).Offset(0, 5)), SortOn:=xlSortOnValues, Order:=xlDescending, _
DataOption:=xlSortNormal
'Worksheets(Tab1).Activate
With ActiveWorkbook.Worksheets(Tab1).AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range(BRS).Select
Selection.Copy
Workbooks(Tgt).Worksheets(Tab2).Activate
With Range(BRT)
.PasteSpecial Paste:=xlPasteValues
End With
End Sub