复制以不同顺序在新工作表中粘贴不同的动态范围

时间:2016-12-16 11:14:18

标签: excel-vba range copy-paste vba excel

我想以不同的顺序将不同的范围和选择区域按照特定顺序复制/粘贴到新工作表中。 使用以下代码我试图实现它,但不幸的是,范围没有完全复制/粘贴在第二张表中。有什么建议吗?

btnNewGame.setOnAction( __ ->
{
    System.out.println( "Restarting app!" );
    primaryStage.close();
    primaryStage.setScene( new Scene( new BorderPane( btnNewGame ) ) );
    primaryStage.show();
} );

1 个答案:

答案 0 :(得分:0)

看看是否有效

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, s(1 To 11) As String, sw As String

sw = "'ZMM17 Unique'!"

' Delete all the cells from the Stock Report
Sheets("Stock Report").Cells(5, 1).CurrentRegion.Delete

' Copy of all the different collumns from ZMM17 Unique sheet
With Sheets("ZMM17 Unique")
    Set RngAA = .Range("AA7:AA" & .Range("AA7").End(xlDown).Row + 3): s(1) = sw & RngAA.Address
    Set RngC = .Range("C7:C" & .Range("C7").End(xlDown).Row + 3): s(2) = sw & RngC.Address
    Set RngR = .Range("R7:R" & .Range("R7").End(xlDown).Row + 3): s(3) = sw & RngR.Address
    Set RngA = .Range("A7:A" & .Range("A7").End(xlDown).Row + 3): s(4) = sw & RngA.Address
    Set RngBDEFG = .Range("B7:G" & .Range("B7").End(xlDown).Row + 3): s(5) = sw & RngBDEFG.Address
    Set RngAF = .Range("AF7:AF" & .Range("AF7").End(xlDown).Row + 3): s(6) = sw & RngAF.Address
    Set RngAI = .Range("AI7:AI" & .Range("AI7").End(xlDown).Row + 3): s(7) = sw & RngAI.Address
    Set RngAL = .Range("AL7:AL" & .Range("AL7").End(xlDown).Row + 3): s(8) = sw & RngAL.Address
    Set RngAMAN = .Range("AM7:AN" & .Range("AM7").End(xlDown).Row + 3): s(9) = sw & RngAMAN.Address
    Set RngSTUVWX = .Range("S7:X" & .Range("S7").End(xlDown).Row + 3): s(10) = sw & RngSTUVWX.Address
    Set RngIJKLM = .Range("I7:M" & .Range("I7").End(xlDown).Row + 3): s(11) = sw & RngIJKLM.Address
End With

For i = 1 To UBound(s)
    Range(s(i)).Copy
   ' paste current range area to first column (using i variable) to "Stock Report" sheet
   Sheets("Stock Report").Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).PasteSpecial Paste:=xlPasteValues
Next i

Sheets("Stock Report").Columns(1).Delete Shift:=xlToLeft

End Sub