Obtaining Data From Another WorkBook

BluesBros

New Member
Joined
Jan 16, 2005
Messages
42
I'm currently using the code below to copy data from another workbook into the current one.

The only problem is that the worksheet in the second book can change name. As there is only ever one sheet in the second book is there anyway to select that sheet automatically and paste into the current workbook?

The current workbook will always have a sheet called "Data".

Workbooks.Open FileToOpen
Sheets("Data").Select
Cells(1, 1).CurrentRegion.Copy Destination:=SourceBook.Sheets("Data").Range("A1:AE65536").End(xlUp).Offset(0, 0)
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
As the single sheet will be the active one you do not need to Select.
If you need this in future, the syntax is:-
Code:
Sheets(1).Select

Looks like an error in your code. With
Code:
.Offset(0, 0)
the bottom row of existing data will be overwritten. Should this be :
Code:
.Offset(1, 0)
 
Upvote 0

Forum statistics

Threads
1,224,395
Messages
6,178,355
Members
452,841
Latest member
GenAkaman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top