高级过滤器数据未复制到范围

时间:2018-01-14 15:13:09

标签: excel vba excel-vba

我正在尝试在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

1 个答案:

答案 0 :(得分:1)

Action:=xlFilterinPlace更改为Action:=xlFilterCopy