繁体   English   中英

从所有工作表复制并粘贴固定行数,然后粘贴到VBA中的一张工作表中

[英]Copy and paste fix number of rows from all the sheets and paste into one sheet in VBA

我想从10张纸上复制(“ A1:A10”)&(“ D1:D10”)列的数据,并将其粘贴到名为(“ New1”)的新表中。 在复制数据时,它不应该考虑新工作表(“ New1”),因为它是结果文件。 并且所有结果应相互叠加

以下是我尝试过的代码。 但是我在“ Next ws”上收到错误“函数未定义”

Dim ws As Worksheet 

Application.DisplayAlerts = False 

For Each ws In ActiveWorkbook.Worksheets 

    Range("b3").Select 
    Range(Selection, Selection.End(xlDown)).Select 
    Selection.Copy 
    Sheets("New1").Select
    Range("A1").Select 
    ActiveSheet.Paste 

Next ws 

Application.DisplayAlerts = True 

End Sub 

您可以使用此:

Dim ws As Worksheet

Application.DisplayAlerts = False

For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> "New1" Then ' if current sheet isn't "New1" one
        With ws ' reference current sheet
            .Range("b3", .Cells(.Rows.Count, "B").End(xlUp)).Copy Destination:=Sheets("New1").Cells(Rows.Count, "A").End(xlUp).Offset(1) ' copy referenced sheet range from B3 down to last not empty cell and paste it form first empty cell of sheet "New1" column A
        End With
    End If
Next ws

Application.DisplayAlerts = True

并轻松调整它以处理不同的复制和粘贴范围

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM