ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   import data (https://www.excelbanter.com/excel-programming/319509-import-data.html)

luc

import data
 
how can I import data from another excel file into an existing excel file.
what would the code look like.



Dave Peterson[_5_]

import data
 
Turn on the macro recorder.
Open both files
copy and paste from one worksheet to another (different workbooks)
stop the recording

look at the code.

I think if you do something like this, you'll see the workbook/worksheet names
that you need.

Post back with any questions you have after you do it.

===
This is what I would do with both workbooks open.

dim fRng as range
dim tRng as range

with workbooks("book1.xls").worksheets("sheet1")
set frng = .range("a1:g9")
end with

with workbooks("book2.xls").worksheets("sheet1")
set trng = .cells(.rows.count,"A").end(xlup).offset(1,0)
end with

frng.copy _
destination:=trng

===

It copies the range, but pastes to the first available cell in column A of the
second worksheet.



luc wrote:

how can I import data from another excel file into an existing excel file.
what would the code look like.


--

Dave Peterson


All times are GMT +1. The time now is 08:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com