我正在尝试在VBA中使用Excel中的高级过滤器,并将过滤后的数据复制到另一个工作簿。代码正在运行但在我选择的目的地中没有副本。我得到一张空白表,我需要看到结果。我检查过,当我手动过滤时,它会向我显示原始位置的rihgt行。 ListsWS
是标准所在的WS,OverWS
是数据存储的位置。我想将过滤后的数据复制到tmpFile
到工作表1这里是我的代码:
Public myExtension As String
Public FullPath As String
Public VisualWB As Workbook
Public tmpFile As Workbook
Public VisualWS As Worksheet
Public LR As Long
Public lastcol As Integer
Public MonCol As Integer
Public Table As Range
Public SigilDes As Integer
Public LR_Over As Long
Sub Export_File()
Set tmpFile = Application.Workbooks.Add
With tmpFile
.Worksheets.Add After:=Worksheets(Worksheets.Count)
.Worksheets(1).Name = "over"
.Worksheets(2).Name = "double"
End With
End Sub
.
.
.
'here is some not relevant code
Sub Analyze_1()
'copy monthly and hourly employees with over 42 to new workbook with advanced filter
With OverWS
LR_Over = .Cells(Rows.Count, "A").End(xlUp).Row
.Range("A1", .Cells(LR_Over, lastcol + 2)).AdvancedFilter Action:=xlFilterInPlace, _
CriteriaRange:=ListsWS.Range("G1:H3"), CopyToRange:=tmpFile.Worksheets(1).Cells(1, 1), Unique:=False
.Visible = False
End With
End Sub
答案 0 :(得分:1)
将Action:=xlFilterinPlace
更改为Action:=xlFilterCopy