+ Reply to Thread
Results 1 to 4 of 4

Error: "PasteSpecial method of Range class failed"

  1. #1
    Registered User
    Join Date
    11-14-2017
    Location
    India
    MS-Off Ver
    MS Office 2013
    Posts
    2

    Error: "PasteSpecial method of Range class failed"

    I have a workbook where I have a loop to copy cell ranges from different workbooks. But I get the "PasteSpecial method of the Range class failed" for a few workbooks. The source workbooks have everything correct.

    Below is the procedure code. Can someone help what I am doing wrong here?


    Please Login or Register  to view this content.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,987

    Re: Error: "PasteSpecial method of Range class failed"

    Comment out the On Error line of code.

    You have two PasteSpecial lines of code. Determine which one is causing the error. If it is the second one, when the error occurs, go into the debugger and determine the address of wR and the value of colOffset at the point where the error occurs. Make sure that the Offset results in a valid Range reference.

    Determine if the destination sheet is protected.

    I do not see Wks declared or defined. What is it?

    Also your code is almost unreadable. You should indent to show structure.

    Also
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    11-14-2017
    Location
    India
    MS-Off Ver
    MS Office 2013
    Posts
    2

    Re: Error: "PasteSpecial method of Range class failed"

    Sorry for the untidy code and thanks for the help. Here is the entire code including the globally defined variables.
    wR is the range in the Data worksheet and the offset is fixed. I am just copying Range C2:C10 and F2:F5 from the source workbooks that I open from Folder and colOffset is 9 as pasting it as transpose to Data worksheet in ThisWorkbook. They are perfectly valid ranges at each iteration.

    I am surprised and confused at what is causing this error. Because sometimes it copies all the workbooks fine without a pastespecial error. But when I run it next time I run it shows a pastespecial error with some random workbook and skips copying data from those random workbooks. This error comes very randomly so I am not able to figure out the cause.

    I even tried which of the two pastespecial is causing the error by appending an integer to log, but that is also random. It's the first line of pastespecial sometimes and the second pastespecial the other time.

    Please Login or Register  to view this content.
    Last edited by MITH_N; 06-02-2023 at 10:41 AM.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,987

    Re: Error: "PasteSpecial method of Range class failed"

    Did you try any of the troubleshooting steps I suggested? The best way to diagnose an error is to inspect the state of the data at the point where the error occurs.

    Quote Originally Posted by MITH_N View Post
    This error comes very randomly
    I don't see anything inherently wrong in the code. If the error is not reproducible it would be hard to solve it just by reading the code. I would have to see the error occur.

+ 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 help "Select Method of Range Class Failed"
    By mongoose36 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-03-2014, 11:39 AM
  2. Runtime Error 1004 "Active method of range class failed".
    By new2excel2012 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-14-2012, 07:55 AM
  3. [SOLVED] "Pastespecial Method of Range Class Failed" while trying to Transpose
    By tenscourts in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-02-2012, 02:37 PM
  4. Error Using filters "Method of range class failed"
    By papermoon in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-12-2010, 10:07 AM
  5. Runtime Error "1004" Autofill Method of range class failed
    By DonKarlos in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-15-2009, 07:44 PM
  6. "Select method of range class failed" error
    By RBI in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-22-2008, 10:28 AM
  7. [SOLVED] "PasteSpecial method of Range class failed"
    By Shaka215@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-21-2006, 06:45 AM
  8. Help: "PasteSpecial method of Range class failed"
    By PropKid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-13-2005, 09:19 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