Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Macro Copy data between 2 workbooks

Status
Not open for further replies.

Bennie47250

Programmer
Nov 8, 2001
515
US
Using Excel 2002

Working on a macro that will copy data from one workbook to another.

The workbook that the data is copied TO will always be named the same.

The workbook that the data is copied FROM name is always different.

The macro I recorded has the copied FROM sheet referenced as:
Windows("COLUMN MEASUREMENT WITH BRKT~SN0056-3.csv").Activate

As I take it, this macro will only run if the workbook COLUMN MEASUREMENT WITH BRKT~SN0056-3.csv is open. But after I have copied this data, I need to go to another sheet that may be named COLUMN MEASUREMENT WITH BRKT~SN0069-56.csv and so on and so on.

When I run the macro I will only have two workbooks open, the copy to and copy from workbooks.

Is it possible to modify the macro to always go to the only other open workbook, no matter the name and copy the data?
 
The following bit of code should go into the workbook that you are copying to (in my example it is called dom1.xls).

For Each w In Workbooks
If w.Name <> ThisWorkbook.Name Then
Windows(w.Name).Activate
Cells.Select
Selection.Copy
Windows("dom1.xls").Activate
ActiveSheet.Paste
Cells(1, 1).Select
End If
Next w

It's not the neatest bit of code, but it does the job. You should be able to modify it easy enough to meet your requirements though.

Dom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top