+ Reply to Thread
Results 1 to 4 of 4

Run time error 1004

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2019
    Posts
    758

    Run time error 1004

    Hi all,

    I have been running this code with no errors for a while, but this keeps popping up now and I am unsure why:

    Sub Procedure14()
    'Copy to IMEI table
    Application.ScreenUpdating = False
    Sheets("IMEI").Select
        Range("A2").Select
        Range(Selection, Selection.End(xlDown)).Select
        Application.CutCopyMode = False
        Selection.Copy
        Sheets("Start").Select
        Range("L3").Select
        ActiveSheet.Paste
        Sheets("IMEI").Select
        Range("B2").Select
        Range(Selection, Selection.End(xlDown)).Select
        Application.CutCopyMode = False
        Selection.Copy
        Sheets("Start").Select
        Range("N3").Select
        ActiveSheet.Paste
            
    Application.ScreenUpdating = True
    
    End Sub
    I am getting "Run-time error '1004': You can't paste this here because the Copy area and paste area aren't the same size. Select just one cell in the paste area or an area that's the same size, and try pasting again.

    With this line highlighted:

    ActiveSheet.Paste

    Any ideas why?

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,913

    Re: Run time error 1004

    If there is just the one value in column B of the IMEI sheet, i.e. something in B2 but nothing in B3 or below, your xlDown command will copy from there to the very last row in the worksheet. When you try and paste that range into the Start sheet starting at row 3, it will go beyond the limit of Excel and it throws up an error. Microsoft are very well known for their error messages not being particularly helpful, and this is a prime example.

    Give this version a try. It should do all your code does but will cope with there being just one value in either column.
    Sub Procedure14()
        Application.ScreenUpdating = False
        
        With Sheets("IMEI")
            .Range("A2:A" & .Cells(Rows.Count, "A").End(xlUp).Row).Copy Sheets("Start").Range("L3")
            .Range("B2:B" & .Cells(Rows.Count, "B").End(xlUp).Row).Copy Sheets("Start").Range("N3")
        End With
        
        Application.ScreenUpdating = True
    End Sub
    It will obviously still fall over if you have values in EVERY row, but that's unlikely.

    BSB

  3. #3
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2019
    Posts
    758

    Re: Run time error 1004

    Excellent! Thank you so much BadlySpelledBuoy!

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,913

    Re: Run time error 1004

    Happy to help

    BSB

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] I am getting error as "Run Time error '1004' Microsoft excel cannot paste the data
    By Amittapre in forum Excel Programming / VBA / Macros
    Replies: 43
    Last Post: 03-24-2017, 04:40 PM
  2. [SOLVED] Sort Macro Run-time error '1004': Application/Object-defined error.
    By sam1212 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-22-2014, 10:05 AM
  3. Addon error : Run-time error '1004': Method 'MacroOptions' of object '_Application' failed
    By jtcoleman in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 3
    Last Post: 02-05-2014, 12:23 PM
  4. Replies: 4
    Last Post: 11-15-2013, 05:03 PM
  5. VBA Code...error = run time error 1004 autofilter method of range class failed
    By Dariusd7 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-15-2013, 04:49 PM
  6. Error "run-time Error '1004': General Odbc Error
    By D4WNO77 in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-16-2012, 09:55 AM
  7. [SOLVED] run-time error '1004': Application-defined or object-deifined error
    By rich5665@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-10-2005, 05:05 PM

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