简体   繁体   中英

Copying data from one sheet to another workbook

How do I go about copying data from one file to another using VBA? When I run this code I get an error - "run-time error '1004' : application defined or object-defined error". I am using Excel 2010

Sub nextfile()

    Range("B5").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Copy
    Windows("MAIN Pivot Table.xlsx").Activate
    Range("B5").Select
    ActiveSheet.Paste
End Sub

sure the error is because you try to copy over 2500 rows and you are using office 2003 has some limitations

Best Fix it with a loop

Range(Range("A" & ActiveCell.Row), Range("IV" & ActiveCell.Row).End(xlToLeft)).Select

To avoid this problem if the VBA macro to copy and paste a range of 2,516 rows or more rows, change the code in a loop VBA macro to copy and paste smaller ranges until data is copied and pasted the desired range.

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