![](/img/trans.png)
[英]Copy/paste values from multiple sheets, but not all sheets, into one sheet
[英]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.