Error when switching between workbooks

Patricia0923

New Member
Joined
Mar 18, 2014
Messages
25
Hi,
I need to transfer data from a workbook named R2D2 to one named Matrix.
It runs after a change event (date data inputted into cell C1).

The code looks like this:

Dim R2D2data As String
Dim Matrix As String

R2D2data = "C:\Users\Owner\Desktop\Excel Projects\R2D2.xlsx"
Matrix = "Matrix Text.xlsm"

Workbooks.Open Filename:=R2D2data
Range("B2:G2").Select
Application.CutCopyMode = False
Selection.Copy

Workbooks(Matrix).Activate
Range("B4:G4").Select
ActiveSheet.Paste

Workbooks.(R2D2data).Activate I get a Run-time error '9' Subscript out of range error here
Range("B3:G3").Select
ActiveSheet.Paste

I need to be able to go back and forth to the R2D2data file many times to extract various pieces of data.

Any help would be appreciated
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Try this,

Code:
Dim R2D2data As Workbook '// Define workbook Variable


Set R2D2data = Workbooks.Open("C:\Users\Owner\Desktop\Excel Projects\R2D2.xlsx") 'set the variable to R2D2.xlsx




Range("B2:G2").Select
Application.CutCopyMode = False
Selection.Copy


ThisWorkbook.Activate '// same as your Workbooks(Matrix).Activate
Range("B4:G4").Select
ActiveSheet.Paste


R2D2data.Activate
Range("B3:G3").Select
ActiveSheet.Paste
 
Upvote 0
Try this,

Code:
Dim R2D2data As Workbook '// Define workbook Variable


Set R2D2data = Workbooks.Open("C:\Users\Owner\Desktop\Excel Projects\R2D2.xlsx") 'set the variable to R2D2.xlsx




Range("B2:G2").Select
Application.CutCopyMode = False
Selection.Copy


ThisWorkbook.Activate '// same as your Workbooks(Matrix).Activate
Range("B4:G4").Select
ActiveSheet.Paste


R2D2data.Activate
Range("B3:G3").Select
ActiveSheet.Paste


Hi,
Thank you very much I will try it and see.
Right now my Excel 365 has just stopped working!?
I have this weird lock and key in the name box and the cells are all greyed out?
 
Upvote 0
Hi,
Thank you very much I will try it and see.
Right now my Excel 365 has just stopped working!?
I have this weird lock and key in the name box and the cells are all greyed out?


Hi again,
Just following up again - I added the code and it worked perfectly!!

Thanks so much!

Tricia
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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