VBA: Copying data from another opened workbook to the current workbook

donatepresent

New Member
Joined
Oct 4, 2017
Messages
21
Hi Everyone,

I need help figuring out how to copy a fixed data range from another Workbook with a fixed file name (i.e. COA.xlms) and paste to the current/master/active Workbook that does not have a fixed file name(dynamic). Both Workbook will already be open, but the problem for me is how to get the copied data back to the current/master/active Workbook that the VBA is running on.

Thanks,
Ken
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Saurabhj

Active Member
Joined
Jun 6, 2020
Messages
413
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi Ken,

As per my understanding you want to copy the fixed data range from COA.xlms in another file (the file name can be different).

Is my understanding correct ?

Thanks,
Saurabh
 

donatepresent

New Member
Joined
Oct 4, 2017
Messages
21
Hi Ken,

As per my understanding you want to copy the fixed data range from COA.xlms in another file (the file name can be different).

Is my understanding correct ?

Thanks,
Saurabh
Copy fixed data range from COA.xlms to the main Workbook that can have different file name.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,451
Office Version
  1. 365
Platform
  1. Windows
Is the code in the workbook you want to copy to?
Also what are the sheet names & the range to be copied?
 

donatepresent

New Member
Joined
Oct 4, 2017
Messages
21

ADVERTISEMENT

Is the code in the workbook you want to copy to?
Also what are the sheet names & the range to be copied?
In my personal macro, so yes the code is ran on the master workbook and I want to copy from another workbook COA.xlms with sheet name "Budget" and Range A1:I36.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,451
Office Version
  1. 365
Platform
  1. Windows
Is the code in the master workbook, or your in your personal.xlsb workbook?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,451
Office Version
  1. 365
Platform
  1. Windows
Because it depends on how the code is written. It would be easier & safer if the code was in the master workbook.
How about
VBA Code:
Sub donatepresent()
   With ActiveWorkbook.Sheets("Sheet1")
      Workbooks("COA.xlsm").Sheets("Budget").Range("A1:I36").Copy .Range("A1")
   End With
End Sub
The master workbook must be the activeworkbook when the code is run. Change Sheet1 to suit.
 
Solution

donatepresent

New Member
Joined
Oct 4, 2017
Messages
21
Because it depends on how the code is written. It would be easier & safer if the code was in the master workbook.
How about
VBA Code:
Sub donatepresent()
   With ActiveWorkbook.Sheets("Sheet1")
      Workbooks("COA.xlsm").Sheets("Budget").Range("A1:I36").Copy .Range("A1")
   End With
End Sub
The master workbook must be the activeworkbook when the code is run. Change Sheet1 to suit.

The sheet I want it to apply to is Sheet5, so I changed Sheet1 to Sheet5, but I don't see the copy and paste data from COA.xlsm. Also, I want the paste to go in cell "I3" of Sheet5.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,451
Office Version
  1. 365
Platform
  1. Windows
In that case change .Range("A1") to .Range("I3")
 

Watch MrExcel Video

Forum statistics

Threads
1,129,323
Messages
5,635,603
Members
416,869
Latest member
JeffK26

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
Top