您好我有以下代码将数据从sheet1复制到工作表2.所有列都被选中,如何修改以仅选择A,I和M列:
Sub NewSheetData()
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Dim Rng As Range
Set Rng = Range([A1], Range("A" & Rows.Count).End(xlUp))
On Error Resume Next
With Rng
.AutoFilter , field:=1, Criteria1:="*TC*", Operator:=xlOr
.SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets("Sheet2").Range("A1")
.AutoFilter
End With
On Error Goto 0
Application.EnableEvents = True
答案 0 :(得分:1)
您可以像这样执行单独的复制粘贴:
With Rng
.AutoFilter , field:=1, Criteria1:="*TC*", Operator:=xlOr
.SpecialCells(xlCellTypeVisible).Range("A1").Copy Sheets("Sheet2").Range("A1")
.SpecialCells(xlCellTypeVisible).Range("I1").Copy Sheets("Sheet2").Range("B1")
.SpecialCells(xlCellTypeVisible).Range("M1").Copy Sheets("Sheet2").Range("C1")
.AutoFilter
End With
编辑: 你也可以尝试:
Sheets("Sheet1").Range("A1").SpecialCells(xlCellTypeVisible).Copy Sheets("Sheet2").Range("A1")
Sheets("Sheet1").Range("I1").SpecialCells(xlCellTypeVisible).Copy Sheets("Sheet2").Range("A1")
Sheets("Sheet1").Range("M1").SpecialCells(xlCellTypeVisible).Copy Sheets("Sheet2").Range("A1")