+ Reply to Thread
Results 1 to 8 of 8

Copy Data outside Excel and PasteSpecial inside Worksheet - Run-time error '1004'

  1. #1
    Registered User
    Join Date
    09-04-2014
    Location
    FL
    MS-Off Ver
    2010
    Posts
    3

    Copy Data outside Excel and PasteSpecial inside Worksheet - Run-time error '1004'

    Hello, I am trying to create a macro in my Personal.xlsb that will

    1. Clear all data in worksheet except row 1 (done)
    2. Select a cell where new data will be pasted (done)
    3. Paste data from Clipboard via PasteSpecial Paste:=xlPasteValues (failed)

    Before I run the macro I have copied in the clipboard data from another program, when I run the macro it does everything except pasting, I get the following error:

    Run-time error '1004' - PasteSpecial method of Range class failed

    Sub DeleteAndPaste()

    Rows(1).Offset(1, 0).Resize(Rows.Count - 1).ClearContents
    Range("A2").Select
    'Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

    End Sub

    I checked and there is data in the clipboard, and I confirmed this by doing a manual paste special into the cell after the macro failed and it works, but not from the macro. Any help is greatly appreciated.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Copy Data outside Excel and PasteSpecial inside Worksheet - Run-time error '1004'

    try range("a2").pastespecial
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copy Data outside Excel and PasteSpecial inside Worksheet - Run-time error '1004'

    Where is the copy command(Method)?

  4. #4
    Registered User
    Join Date
    09-04-2014
    Location
    FL
    MS-Off Ver
    2010
    Posts
    3

    Re: Copy Data outside Excel and PasteSpecial inside Worksheet - Run-time error '1004'

    AB33

    Where is the copy command(Method)?


    I am manually copying from another program and leaving the data ready in the clipboard

    nathansav

    try range("a2").pastespecial


    This worked but I need to paste the values only, no formatting, or it can also be Match Destination Formatting (M)

    It seems the Paste:=xlPasteValues is what makes it fail, any suggestions?

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copy Data outside Excel and PasteSpecial inside Worksheet - Run-time error '1004'

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-04-2014
    Location
    FL
    MS-Off Ver
    2010
    Posts
    3

    Re: Copy Data outside Excel and PasteSpecial inside Worksheet - Run-time error '1004'

    As soon as I add xlValues after PasteSpecial it gives me the Run-time error '1004', weird.

    It works just by having Range("a2").PasteSpecial

    for now I can survive with just that, it's annoying to have all the cells resized after paste but at least it works

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copy Data outside Excel and PasteSpecial inside Worksheet - Run-time error '1004'

    I suspect the clipboard method works the same way as "Cut" method

  8. #8
    Registered User
    Join Date
    03-16-2021
    Location
    Porto, Portugal
    MS-Off Ver
    2016
    Posts
    1

    Re: Copy Data outside Excel and PasteSpecial inside Worksheet - Run-time error '1004'

    Hi, I have the exact same problem.
    PasteSpecial xlvalues works fine if I try to copy data from the Excel, but as soon as I try to copy data outside excel this line gives me an error.

    And in my case I really need to force the paste as values option.
    Any ideia how to solve this?

  9. #9
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,023

    Re: Copy Data outside Excel and PasteSpecial inside Worksheet - Run-time error '1004'

    Quote Originally Posted by rui.alheiro View Post
    Hi, I have the exact same problem.
    PasteSpecial xlvalues works fine if I try to copy data from the Excel, but as soon as I try to copy data outside excel this line gives me an error.

    And in my case I really need to force the paste as values option.
    Any ideia how to solve this?
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ 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] VBA Run-time error '1004': PasteSpecial method of Range class failed on 2nd run
    By hydz1213 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-05-2013, 11:05 AM
  2. Run time error 1004 - PasteSpecial of Range class failed
    By Niciana in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-09-2012, 11:45 AM
  3. Run-time error '1004' PasteSpecial
    By STarloff in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-27-2010, 10:14 AM
  4. Excel Run time Error 1004: Copy method of Worksheet Class failed
    By chrismann85 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-30-2008, 06:05 AM
  5. [SOLVED] Run-Time error'1004' PasteSpecial Method of Worksheet class failed
    By gj in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-31-2006, 06:48 AM

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