且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Excel宏可将数据从一个工作表复制并粘贴到另一工作表

更新时间:2022-12-11 23:22:11

尝试使用此简化版本:

Sub CopyData()

    '// Turn off screen updating for cosmetics
    Application.ScreenUpdating = False

    Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "MySheet"

    '// Change this to your sheet you are copying from
    With Sheet1
        '// Filter all rows with Mail Box
        .Range("E:E").AutoFilter Field:=1, Criteria1:="Mail Box", Operator:=xlAnd
        '// Copy all rows except header
        .UsedRange.Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Copy Worksheets("MySheet").Cells(2, 1)
        '// Remove the autofilter
        If .AutoFilterMode Then .AutoFilterMode = False
     End With

    Application.ScreenUpdating = True

    MsgBox "All matching data has been copied."

End Sub