我正在按照特定的順序將不同的範圍和選擇區域以不同的順序複製/粘貼到新的工作表中。 使用下面的代碼我試圖實現它,但不幸的是,範圍沒有完全複製/粘貼在第二張紙上。任何建議?以不同的順序將不同的動態範圍粘貼到新的工作表中
Sub MultipleRanges()
Dim RngAA As Range, RngC As Range, RngR As Range, RngA As Range, RngBDEFG As Range, RngAF As Range, RngAI As Range, _
RngAL As Range, RngAMAN As Range, RngSTUVWX As Range, RngIJKLM, UnionRng As Range
Dim i As Long
' Delete all the cells from the Stock Report
Cells(5, 1).CurrentRegion.Select
Selection.Delete
' Copy of all the different collumns from ZMM17 Unique sheet
Set RngAA = Sheets("ZMM17 Unique").Range("AA7:AA" & Sheets("ZMM17 Unique").Range("AA7").End(xlDown).Row + 3)
Set RngC = Sheets("ZMM17 Unique").Range("C7:C" & Sheets("ZMM17 Unique").Range("C7").End(xlDown).Row + 3)
Set RngR = Sheets("ZMM17 Unique").Range("R7:R" & Sheets("ZMM17 Unique").Range("R7").End(xlDown).Row + 3)
Set RngA = Sheets("ZMM17 Unique").Range("A7:A" & Sheets("ZMM17 Unique").Range("A7").End(xlDown).Row + 3)
Set RngBDEFG = Sheets("ZMM17 Unique").Range("B7:G" & Sheets("ZMM17 Unique").Range("B7").End(xlDown).Row + 3)
Set RngAF = Sheets("ZMM17 Unique").Range("AF7:AF" & Sheets("ZMM17 Unique").Range("AF7").End(xlDown).Row + 3)
Set RngAI = Sheets("ZMM17 Unique").Range("AI7:AI" & Sheets("ZMM17 Unique").Range("AI7").End(xlDown).Row + 3)
Set RngAL = Sheets("ZMM17 Unique").Range("AL7:AL" & Sheets("ZMM17 Unique").Range("AL7").End(xlDown).Row + 3)
Set RngAMAN = Sheets("ZMM17 Unique").Range("AM7:AN" & Sheets("ZMM17 Unique").Range("AM7").End(xlDown).Row + 3)
Set RngSTUVWX = Sheets("ZMM17 Unique").Range("S7:X" & Sheets("ZMM17 Unique").Range("S7").End(xlDown).Row + 3)
Set RngIJKLM = Sheets("ZMM17 Unique").Range("I7:M" & Sheets("ZMM17 Unique").Range("I7").End(xlDown).Row + 3)
Set UnionRng = Union(RngAA, RngC, RngR, RngA, RngBDEFG, RngAF, RngAI, RngAL, RngAMAN, RngSTUVWX, RngIJKLM)
' For debug only
Debug.Print UnionRng.Address
For i = 1 To UnionRng.Areas.Count
' copy current range area from Union Range
UnionRng.Areas(i).Copy
' paste current range area to first column (using i variable) to "Stock Report" sheet
Sheets("Stock Report").Range(Cells(3, i), Cells(3, i)).PasteSpecial Paste:=xlPasteValues
Next i
End Sub
一些要複製的範圍是幾列寬,但是當你粘貼你只用一列遞增? – SJR