+ Reply to Thread
Results 1 to 19 of 19

Code doesn't copy the data without any errors

  1. #1
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Code doesn't copy the data without any errors

    Hi, I hope someone can point out to me what I am doing wrong. I have the following code, that works without error except for the red part. It doesn't copy the data over and no error is displayed. What is going on?

    Please Login or Register  to view this content.
    Click the * to say thanks.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: Code doesn't copy the data without any errors

    Attach the workbook, please.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Code doesn't copy the data without any errors

    I'm sorry, but I cannot attach none of them due to the fact that both contain a lot of sensitive data

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: Code doesn't copy the data without any errors

    Then attach a desensitised version that displays the issue.

  5. #5
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Code doesn't copy the data without any errors

    Comment out the On Error Resume Next line, which is why you aren't seeing any errors, then rerun the code and tell us the error message. At a guess I'd say the pivot table names are wrong, unless you manually added a full stop to them.
    Rory

  6. #6
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Code doesn't copy the data without any errors

    rorya, you are correct. I actually changed the pivot tables names and I forgot about it. Now it works, but the strangest part is that is copying only the data for pivot4, and not for the rest of them

  7. #7
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Code doesn't copy the data without any errors

    Is that with the On error commented out?

  8. #8
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Code doesn't copy the data without any errors

    Yes. only the last pivot data gets copied and pasted. All of them have the same format, 2 filters and 1 header line. the rows are different, but shouldn't be a problem. My guess is that it has something to do with the Offset but I don't know

  9. #9
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Code doesn't copy the data without any errors

    If you don't want the filter fields, you'd be better off using Tablerange1 as a starting point:

    Please Login or Register  to view this content.
    I'd probably also refactor this part as you're basically doing the same operations each time.
    Last edited by rorya; 07-15-2019 at 06:15 AM.

  10. #10
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Code doesn't copy the data without any errors

    rorya, you are absolutely amazing. many thanks for it. solved my issue

  11. #11
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Code doesn't copy the data without any errors

    Glad to help.

    Here's a refactored version. Add this routine:

    Please Login or Register  to view this content.
    then the code I posted earlier just becomes:

    Please Login or Register  to view this content.

  12. #12
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Code doesn't copy the data without any errors

    This is even better rorya. I have another question. How can I paste a pivot as values, then define the lastrow in the worksheet in which it was pasted and paste a second one 3 rows below it?

  13. #13
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Code doesn't copy the data without any errors

    If there's a column that will always be populated for every row of the pasted data, you can use that to find the last populated row and then offset by 3.

  14. #14
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Code doesn't copy the data without any errors

    Taught so, so I wrote it like this:
    Please Login or Register  to view this content.
    But the line in red gives me an error. If I add B:B instead it will populate the rows starting in B1 unstead as I have blanks between B1 and B8. Any ideas why?

  15. #15
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Code doesn't copy the data without any errors

    You've already found the cell to paste to, so just use it:

    Please Login or Register  to view this content.

  16. #16
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Code doesn't copy the data without any errors

    That fixed the error, but it doesn't copy the pivot table which is really weird

  17. #17
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Code doesn't copy the data without any errors

    If you're not getting an error, it must be going somewhere - I'd assume to whatever sheet is active at the time. This part:

    Please Login or Register  to view this content.
    should read:

    Please Login or Register  to view this content.
    {the red part is the most important change)

  18. #18
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Code doesn't copy the data without any errors

    you sir, are amazing! many thanks for everything

  19. #19
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Code doesn't copy the data without any errors

    Glad to help.

+ 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. Code to copy errors to columns
    By ironfelix717 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-29-2018, 03:21 PM
  2. [SOLVED] Why does this code doesn't copy a simple Matrix?
    By Noon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-19-2015, 05:06 AM
  3. [SOLVED] VBA code doesn't remember data
    By minifreak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-19-2013, 04:56 AM
  4. [SOLVED] New Code Copy Doesn't Work properly
    By Kyle123 in forum Suggestions for Improvement
    Replies: 3
    Last Post: 07-18-2012, 08:00 AM
  5. Copy a new worksheet and the code doesn't work.
    By Wayne555 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-20-2010, 09:28 AM
  6. Copy + Paste doesn't work when I run this code...
    By wildjester in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-21-2009, 03:57 PM
  7. VBA Code for Copy Paste doesn’t work
    By Shark Man in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-16-2009, 02:37 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