copying data from one book to another

G

Gareth

I want to import some info from book2 into book1, I thought it could be done
by having both files open at the same time and running a macro form book1.

The information to copy/import is in cells or ranges of cells. For example,
cell D12 (sheet1) in book2 needs to go into cell C4 (sheet1) in book1.
There are about 150 values to be copied/imported all together.

That's about as far as I have got and any help would be gratefully received.

Gareth
 
T

Tom Ogilvy

Workbooks("Book2.xls").Worksheets("Sheet1").Range("D12").Value = _
Workbooks("Book1.xls").Worksheets("Sheet1").Range("C4").Value
 
R

Richard Buttrey

obviously I misled you........

the files names will not always be known.

Gareth


Gareth

The general approach I always adopt in this situation is as follows.

Sub testcopy()
Dim mywb As Workbook
Dim tempwb As Workbook

Set mywb = ActiveWorkbook
Application.Workbooks.Open ("book2.xls")
<or if you don't know the filename so that you can code it>
Application.GetOpenFilename

Set tempwb = ActiveWorkbook
Worksheets("sheet1").Range("d12").Copy
mywb.Activate
Worksheets("sheet1").Range("c4").PasteSpecial (xlPasteAll)
End Sub


You'd need to adapt this approach to deal with the 150 cells you're
trying to handle, but it shouldn't be too difficult.


Rgds







__
Richard Buttrey
Grappenhall, Cheshire, UK
__________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top