"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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

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