+ Reply to Thread
Results 1 to 7 of 7

Error in macro when auto-pasting code

  1. #1
    Registered User
    Join Date
    01-09-2014
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    77

    Error in macro when auto-pasting code

    Hey all,

    I'm new to VBA but have had it working well for me until the other night when a user complained that when he ran a macro, it came up with the error "Paste method of Worksheet class failed". I should note that this function has worked time and time again, so I'm lost as to why it just started. I also found tonnes of answers with a Google search but they were all relative to that persons code.

    So this is the code I am using to paste from the clipboard into another tabbed worksheet (apologies if the code is horrible) - Also the part where the debugger stops (and highlights) is ActiveSheet.Paste

    Please Login or Register  to view this content.
    Thank you for any help!

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,346

    Re: Error in macro when auto-pasting code

    Did you add this line recently?

    Please Login or Register  to view this content.
    Any action other than selecting will clear the clipboard.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    01-09-2014
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: Error in macro when auto-pasting code

    Quote Originally Posted by Bernie Deitrick View Post
    Did you add this line recently?

    Please Login or Register  to view this content.
    Any action other than selecting will clear the clipboard.
    Yes I added that around two weeks ago and it seemed to be working perfectly prior to just the other day. I need the data that was previously in that range to be cleared before the data in a separate workbook is pasted.. Is that possible?

    Thanks for your help.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,346

    Re: Error in macro when auto-pasting code

    Sure - the best way is to clear it first before copying, but to not change your workflow, we can check after the paste for the cells that were not pasted into....

    Please Login or Register  to view this content.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Error in macro when auto-pasting code

    I think someone here might have a similar problem.
    Last edited by Norie; 06-05-2014 at 07:14 AM.
    If posting code please use code tags, see here.

  6. #6
    Registered User
    Join Date
    01-09-2014
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: Error in macro when auto-pasting code

    Quote Originally Posted by Bernie Deitrick View Post
    Sure - the best way is to clear it first before copying, but to not change your workflow, we can check after the paste for the cells that were not pasted into....

    Please Login or Register  to view this content.
    Thank you, that worked perfectly, enjoy some +rep! So can anyone explain to me why this would have worked for the past few months, but then all of a sudden it became a problem? Or at least can anyone confirm my understanding of this - that the code I had also cleared the clipboard, thus when it went to paste there was nothing to actually paste.. right?

    Which brings me back to being confused because it worked for so long..

    Anyway thanks again!

    Oops I must have posted the thread twice by accident? My bad, sorry!

  7. #7
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,346

    Re: Error in macro when auto-pasting code

    The only reason that I can think of that could have led you to think the macro worked is that you have multiple versions of the macro, some changed and some not, in different versions of the workbook. The .Clear command will always clear the clipboard.

  8. #8
    Registered User
    Join Date
    01-09-2014
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: Error in macro when auto-pasting code

    Quote Originally Posted by Bernie Deitrick View Post
    The only reason that I can think of that could have led you to think the macro worked is that you have multiple versions of the macro, some changed and some not, in different versions of the workbook. The .Clear command will always clear the clipboard.
    Hmmm strange. I will have to have a play around and see what I can find.

    Truly appreciate the help, Bernie! Cheers mate!

+ 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. Error in macro when auto-pasting code
    By Reapz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-04-2014, 11:26 AM
  2. Replies: 3
    Last Post: 02-09-2011, 08:40 PM
  3. Code not copying and pasting data - basic error?
    By Kayote in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-23-2008, 10:57 AM
  4. Error in Code - Pasting Values
    By Janet H in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-01-2005, 05:05 PM
  5. [SOLVED] Excel 1004 Error When Pasting Special W/ Macro
    By setoFairfax in forum Excel General
    Replies: 2
    Last Post: 04-27-2005, 10:06 AM

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