简体   繁体   中英

how to select and copy range of data through vba

I am getting stuck on a simple line of code. For this section of my procedure I simply want to merge data from one tab to another. Below is the code i have to copy the information from "Page1-2" and paste in at the next blank row of "Page1-1":

Sheets("Page1-2").Activate
ActiveSheet.Range("A5:AJ66000").Copy
Sheets("Page1-1").Activate
Columns("A").Find("", Cells(Rows.Count, "A")).Select
ActiveCell.PasteSpecial

Any help on this issue would be greatly appreciated.

Thanks!

I would create a variable to hold the last row in your Page1-1 sheet.

Sub test()
Dim k   As Integer

Sheets("Page1-2").Range("A5:AJ66000").Copy
With Sheets("Page1-1")
    k = .Cells(1048576, 1).End(xlUp).Row
    If k > 1 Then k = k + 1  ' this is so we don't overwrite the last row on previously copied data
    .Cells(k, 1).PasteSpecial
End With
End Sub
    End Sub

Note: It's a good idea to learn how to avoid using .Select , you can see in my code above how to combine those two lines into one.

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