简体   繁体   中英

Excel VBA copy from one workbook into another

I need to copy data from one workbook into another workbook. The copy should be from cell A2 to the last cell used. The paste should be into cell A2.

When I use this line I get an error. Please help. My head hurts!

  Workbooks("ClientData.xls").Worksheets("ClientInfo").Range("A2").SpecialCells(x1CellTypeLastCell).Address.Copy Workbooks("BGA Client Bio May2016v4.xlsm").Worksheets("ClientInfo").Range("A2")

The use of specialcells you are using will only grab tha last cell not the whole range.

You also do not need or want the Address

This will do what you want

With Workbooks("ClientData.xls").Worksheets("ClientInfo")   
    .Range("A2",.Cells(.Rows.Count,1).End(xlUp)).Copy Workbooks("BGA Client Bio May2016v4.xlsm").Worksheets("ClientInfo").Range("A2")
End with

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