+ Reply to Thread
Results 1 to 4 of 4

Object Required - VBA error

Hybrid View

Rutger54 Object Required - VBA error 01-10-2012, 05:37 PM
TMS Re: Object Required - VBA... 01-10-2012, 05:44 PM
Rutger54 Re: Object Required - VBA... 01-10-2012, 06:43 PM
TMS Re: Object Required - VBA... 01-10-2012, 07:43 PM
  1. #1
    Registered User
    Join Date
    01-10-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Object Required - VBA error

    I need to copy from anohter workbook on my I:/ drive and paste into "Sheet 1". I have a code below but get an "Object Required Error. Thank you in advance for any help!

    The code I have is:
    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
    Thanks again!
    Last edited by Leith Ross; 01-11-2012 at 02:59 AM. Reason: Added Code Tags

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,495

    Re: Object Required - VBA error

    Welcome to the forum. Unfortunately:

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-10-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Object Required - VBA error

    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
    Last edited by Leith Ross; 01-11-2012 at 03:00 AM. Reason: Added Code Tags

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,495

    Re: Object Required - VBA error

    Thank you for sharing the solution to your problem. However ...

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    Your post does not comply with Rule 7 of our Forum RULES. Please do not ignore Moderators' or Administrators' requests - note that this includes requests by senior members as well, if you are unclear about their request or instruction then send a private message to them asking for help. Do not post a reply to a thread where a moderator has requested an action that has not been complied with e.g Title change or Code tags...etc

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1