简体   繁体   中英

Copy multiple ranges of cells in one workbook and paste to two different sheets in another workbook

I have one workbook that I want to copy two different selections and paste into two different sheets in a different workbook.

I want to run this multiple times and want it to paste the selected ranges into subsequent BLANK rows, instead of overwriting a previously pasted row. This is what I have:

    Range("BJ8:EB8").Copy
    Windows("LPI Table 2016.xlsx").Activate
    Sheets("LPI 2.4").Select
    Range("A3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
         :=False, Transpose:=False
    Windows("NEW LPI-Sheet_011915.xlsm").Activate
    Range("BJ12:EB12").Copy
    Windows("LPI Table 2016.xlsx").Activate
    Sheets("LPI 2.6").Select
    Range("A3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

End Sub

Instead of

`Range("A3").Select`

use

`Cells(Rows.Count, 1).End(xlUp).Offset(1,0).Select`

Also, try to not use Select statement. It slows down your macro and is usually not necessary. You can rewrite this

Sheets("LPI 2.4").Select
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

and put it all in one line

Sheets("LPI 2.4").Cells(Rows.Count, 1).End(xlUp).Offset(1,0).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM