+ Reply to Thread
Results 1 to 4 of 4

Thread: compile error with copy to different workbook

  1. #1
    Registered User
    Join Date
    06-02-2010
    Location
    Grand Rapids, Michigan
    MS-Off Ver
    Excel 2003
    Posts
    64

    compile error with copy to different workbook

    I am trying to put togher a macro that will copy a range from a workbook and add it to a history report that will store the data. I want the code to add the data to the next row down and leave the previous data the way it was. However I am stuck and am getting a complie error on this part of the code:
    DestBook.Worksheets(1).Range("A" & Rows.Count).End(xlUp)(2, 1)
    Here is the full code:
    Sub CopyData()
    Dim DestBook As Workbook, SrcBook As Workbook
    
    Application.ScreenUpdating = False
    Set SrcBook = ThisWorkbook
    
    On Error Resume Next
    Set DestBook = Workbooks.Open("I:\sctest.xls")
    SrcBook.Worksheets(1).Range("A1:F1").Copy
    Application.CutCopyMode = False
    DestBook.Worksheets(1).Range("A" & Rows.Count).End(xlUp)(2, 1)
    Application.CutCopyMode = False
    DestBook.Save
    DestBook.Close
    End If
    On Error GoTo 0
    Set DestBook = Nothing
    Set SrcBook = Nothing
    End Sub
    I am still learning vba and having a hard time with this
    Any help would be wonderful.

  2. #2
    Forum Guru mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    2,998

    Re: complie error with copy to different workbook vba

    That bit of code describes a cell, but it doesn't say what to do with it.

    Perhaps
    DestBook.Worksheets(1).Range("A" & Rows.Count).End(xlUp)(2, 1).Paste
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    06-02-2010
    Location
    Grand Rapids, Michigan
    MS-Off Ver
    Excel 2003
    Posts
    64

    Re: compile error with copy to different workbook

    Wow I can't believe i missed that. thanks.

  4. #4
    Registered User
    Join Date
    06-02-2010
    Location
    Grand Rapids, Michigan
    MS-Off Ver
    Excel 2003
    Posts
    64

    Re: compile error with copy to different workbook

    That wasn't working either. I tried playing with it for a while and now i'm getting an
    Object doesn't support this property or method on the same line.
    This is what the code looks like right now:
    Sub CopyData()
    Dim DestBook As Workbook, SrcBook As Workbook
    
    Application.ScreenUpdating = False
    Set SrcBook = ThisWorkbook
    SrcBook.Sheets(1).Range("A1:F1").Copy
    Set DestBook = Workbooks.Open("I:\sctest.xls")
    DestBook.Sheets(1).Range("A" & Rows.Count).End(xlUp)(2, 1).Paste
    Application.CutCopyMode = False
    
    DestBook.Save
    DestBook.Close
    End Sub

+ 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.2.0