+ Reply to Thread
Results 1 to 4 of 4

Macro VBA Copy Paste Across Sheets Runtime '1004'

Hybrid View

  1. #1
    Registered User
    Join Date
    04-17-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2003, 2007
    Posts
    8

    Macro VBA Copy Paste Across Sheets Runtime '1004'

    I need help with a Macro I created to automate some processes.

    MSQuery populates in worksheet 1
    Data is copied and pasted into first open cell of worksheet 2 when I get to the paste portion I receive: runtime error '1004' "The information cannot be pasted because the Copy area and the aste area are not.....".

    I am using this for multiple worksheets

    My code is below.

    Sub REFRESH()
    
        Sheets("import_DataSet1").Visible = True
        ActiveWorkbook.RefreshAll
        
        Sheets("import_DataSet1").Select
        Range("A2").Select
        Range(Selection, Selection.End(xlDown)).Select
        Range(Selection, Selection.End(xlToRight)).Select
        Selection.Copy
        Sheets("Data Paste").Select
        Range("B2").Select
        Selection.End(xlDown).Offset(1, 0).Select
        ActiveSheet.Paste
        Application.CutCopyMode = False
        
    
    End Sub
    Moderator's Edit: Use code tags whenever you post code in posts. To do so, either select your code and click the # button above or type [code] before your code and [/code] after it.
    Last edited by arlu1201; 10-31-2012 at 11:36 AM.

  2. #2
    Registered User
    Join Date
    04-17-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2003, 2007
    Posts
    8

    Re: Macro VBA Copy Paste Across Sheets Runtime '1004'

    Sorry my mistake the reason I got the error was because during testing I did not have any data being generated and was pasteing blank data. Other than that the above code works. Although are there any suggestions on how to modify for efficiency. The data is coming from Access database.

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Macro VBA Copy Paste Across Sheets Runtime '1004'

    Your code can be re-written as follows -
    Sub REFRESH()
    Dim lrow As Long
    Dim lcol As Long
    
    Sheets("import_DataSet1").Visible = True
    ActiveWorkbook.RefreshAll
    
    With Worksheets("import_DataSet1")
        lrow = .Range("A" & .Rows.Count).End(xlUp).Row
        lcol = .Range("IV1").End(xlToLeft).Column
        .Range(.Cells(2, 1), .Cells(lrow, lcol)).Copy Worksheets("Data Paste").Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
        Application.CutCopyMode = False
    End With
    
    End Sub
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Registered User
    Join Date
    04-17-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2003, 2007
    Posts
    8

    Re: Macro VBA Copy Paste Across Sheets Runtime '1004'

    Thank you Arlette I will try it out!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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