简体   繁体   English

VBA代码将特定的列从工作表1复制到工作表2

[英]vba code to copy specific columns from worksheet1 to worksheet2

Hi I have the following code to copy data from sheet1 to sheet 2. All columns are getting selected, How can I modify to pick column A, I, and M only: 嗨,我有以下代码将数据从工作表1复制到工作表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 

You can do an individual Copy Paste like this: 您可以像这样进行单独的复制粘贴:

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

Edit: you can also try: 编辑:您也可以尝试:

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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 VBA:根据单元格的值将工作表1中的单元格复制到工作表2 - VBA: Copy cell in worksheet1 to worksheet2 based on value of cell excel:使用名称相同的“ worksheet2”中的值修改“ worksheet1”的值 - excel: Modify the values of “worksheet1” using values from “worksheet2” where name is the same 将特定列从excel工作表复制到另一个工作表 - Copy specific columns from excel worksheet to another worksheet Excel VBA-将特定列从一个工作表复制到另一工作表 - Excel VBA - Copying specific columns from one worksheet to another worksheet 将特定的列从工作表复制/粘贴到另一个 - Copy/Paste Specific Columns from a Worksheet to another VBA:将特定范围从多个工作簿复制到一个工作表中 - VBA: Copy specific range from multiple workbooks into one worksheet 来自多个工作表的VBA Excel复制/粘贴特定范围 - VBA Excel Copy/Paste Specific Range from multiple worksheet VBA,将具有公式的列作为值复制到新工作表中 - VBA, copy columns with formulas to new worksheet as values VBA代码可从一个工作表复制数据并将其粘贴到另一工作表的最后一行下方 - VBA code to copy data from one worksheet & paste below last row of another worksheet Excel 2007 VBA代码,如果满足单个条件,则将行从工作表1复制到工作表2 - Excel 2007 VBA Code to Copy Row from Worksheet 1 to Worksheet 2 if single criteria met
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM