"Object Required" Error

Rutger54

New Member
Joined
Jan 6, 2012
Messages
9
I need to copy from anohter workbook on my I:/ drive and paste into "Sheet 1". I have the cde below but get an "Object Required Error. Please help?? Thanks in advance :)


Sub Macro2()


'Assign variable name to Target workbook
Var1 = "ActiveWorkbook.Name"
'Assign variable name to Target range
Var1R = "A1:AD23"

'Open Source WorkBook
Application.Workbooks.Open ("I:\Currency Futures\JPMFI - Currency Futures\PWD BALANCE BY ACCT\PWD_BALANCE_BY_ACCOUNT.csv")

'Assign variable name to Source workbook
Var2 = "PWD_BALANCE_BY_ACCOUNT.csv"
Var2R = "PWD_Balance_By_Account"

'Copy from Source to Target

Sheets(Var2R).Select.Copy
Destination: Workbooks(Var1).Sheets("Sheet1").Paste
'Close Source WorkBook wo/Save
Workbooks(Var2).Close False


End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
One problem is the following line. ActiveWorkbook.Name should not be in quotes.

Code:
Var1 = "ActiveWorkbook.Name"

Gary
 
Upvote 0
Figured this out! Here's what I did for anyone interested!

Sub Macro2()

'Assign variable name to Target workbook
Var1 = ActiveWorkbook.Name
'Assign variable name to Target range
Var1R = "A:AD"

'Open Source WorkBook
Application.Workbooks.Open ("I:\Currency Futures\JPMFI - Currency Futures\PWD BALANCE BY ACCT\PWD_BALANCE_BY_ACCOUNT.csv")

'Assign variable name to Source workbook
Var2 = ActiveWorkbook.Name
Var2R = "PWD_Balance_By_Account"

'Copy from Source to Target
Sheets(Var2R).Columns("A:AD").EntireColumn.Copy _
Destination:=Workbooks(Var1).Sheets("Sheet1").Range(Var1R)

'Close Source WorkBook wo/Save
Workbooks(Var2).Close False
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

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