![](/img/trans.png)
[英]Copy same non contiguous data at same cell address from multiple worksheets and paste in one master worksheet
[英]copy and paste same non contiguous cells from different sheets to master sheet
如何從不同的工作表中復制相同的非連續單元格並逐行粘貼到一個主工作表(“sheet5”)中。
Sub test()
Dim cel As Range, pasteRange As Range
Set pasteRange = ThisWorkbook.Sheets("Sheet5").Range("A2")
For i=1 to 4
For Each cel In ThisWorkbook.Sheets(i).Range("A2, B4, D5, E1, F3")
pasteRange.Value = cel.Value
Set pasteRange = pasteRange.Offset(0, 1)
Next
Next
End Sub
Dim cel As Range, pasteRange As Range
Dim sht As Worksheet
' Do not use 'ThisWorkbook' - what is the macro us ran from another one?
' Use 'ActiveWorkbook' instead or specify its name
Set pasteRange = ActiveWorkbook.Sheets("Sheet5").Range("A2")
'
For Each sht In Sheets
If sht.name <> "Sheet5" Then
For Each cel In sht.Range("A2, B4, D5, E1, F3")
pasteRange.Value = cel.Value
Set pasteRange = pasteRange.Offset(0, 1)
Next
End If
Next
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.