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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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,213,549
Messages
6,114,261
Members
448,558
Latest member
aivin

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