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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy from one Excel Workbook to another Excel Workbook with VBA 1

Status
Not open for further replies.

robin786

MIS
Dec 6, 2012
5
0
0
US
I am using Excel 2010. I have an Excel workbook which has about 10 worksheets.
Each work sheet has a lot of data. There are a lot of cells and a lot of tables..

I also have another Workbook which has the same 10 excel work sheets in it.
However, all the fields in each worksheet are not in the same order as in the original Workbook.

That is, Workbook A field order is not the same order as the workbook B.

Also, the tables are about 30 rows X 20 columns each in both the Excel workbooks. Again, the rows and columns order in both source and destination is not exactly the same.

How can I copy the data from the Source Workbook to Destination workbook.
Please provide Excel VBA Code.

 
HI,

I would not use COPY 'n' PASTE. Rather I'd use queries to the other sheets to bring the data into your workbook in the order you wish.

Data > Get external data > from other sources > Microsoft Query...

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
The query method, as Skip suggests, will give a far better performance solution, and though it may seem tedious with the way the Query tool is setup, it should be the best solution.

If you're determined to use VBA, you'll need some tediously detailed code to make sure everything copies correctly. Basically, the route I'd take on that would be to match up the original column header with the new column header, assuming at least the field names are 100% identical. If they are not 100% identical, then you'll need to get even more tedious, which even more brings back to Skip's suggestion for MS Query.

Be sure to let us know whatever you end up doing.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top