PDA

View Full Version : Copy data from one workbook to another!



jumbel
01-20-2009, 07:32 AM
Hello all,

I have the following situation. I have a workbook1 which runs a macro and gets the data from workbook2. Now, after the macro is run in workbook1, if I make any changes to the data I got from workbook2, it should automatically be updated in workbook2 as well.( workbook2 is not opened).

Tried to find some solution but of no avail!! Please help!!

Regards,
Krishna

lucas
01-20-2009, 08:06 AM
So you want a macro to write to workbook2 before you close workbook 1?

How are you getting the data from workbook2? Is it a cell, a couple of cells, a range, a worksheet, all worksheets, etc.

jumbel
01-20-2009, 08:46 AM
Ye, thats what I meant, the data is a range of data!!

lucas
01-20-2009, 08:55 AM
And that range is: B2:B20 or what?

You have to help some, I can't see your computer.

jumbel
01-20-2009, 08:57 AM
The range is over a single row, say A2:X2.

lucas
01-20-2009, 09:00 AM
Ok, how are you getting data from book 2 to book 1(provide the code)

when writing to book 2 to book 1 do you want it to go to a specific place in book 2? If so where?

lucas
01-20-2009, 10:18 AM
Here is an example of putting the range in the second workbook:
Sub PutDataInClosedWorkbook()
Dim wb As Workbook
Application.ScreenUpdating = False ' turn off the screen updating
Set wb = Workbooks.Open("C:\Temp\data.xls", True, False)
With wb.Worksheets("Sheet1")
' read data from the source workbook
wb.Worksheets("RESULTS").Range("B7", "E36").Formula = ThisWorkbook.Worksheets("Target").Range("B7", "E36").Formula

End With
wb.Save
wb.Close
Set wb = Nothing ' free memory
Application.ScreenUpdating = True ' turn on the screen updating
End Sub