我想从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
答案 0 :(得分:1)
您可以使用:
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
轻松调整它以处理不同的复制和粘贴范围