+ Reply to Thread
Results 1 to 40 of 40

Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot table?

  1. #1
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot table?

    I have a spreadsheet of data that i need to create a pivot table from.

    I have attached the data i use and what the end result looks like also with the macro that runs to create it, my question is how can i speed this macro up, i know there are some functions life trim, & PTC & PT that will help but unsure of what i can do to complete this;

    The macro currently is;

    Please Login or Register  to view this content.
    Any help is greatly appreciated
    Last edited by kenadams378; 05-15-2012 at 04:54 AM. Reason: More Detail

  2. #2
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    I have the attachment if required

  3. #3
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    Is there anyone that can help at all?

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    a sample workbook would sure help but here's my best guess
    Please Login or Register  to view this content.
    Last edited by JosephP; 05-14-2012 at 07:58 AM. Reason: typo
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    There is an error around this line;

    Set pt = pt.CreatePivotTable(TableDestination:=wsPivot.Range("A1"), TableName:="PivotTable", DefaultVersion:=xlPivotTableVersion10)

    Error is a Runtime 91 - Obkect Variable or with block variable not set

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    that ain't the code I posted-it's pc.createpivottable and not pt.createpivottable

  7. #7
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    Set pc = pc.CreatePivotTable(TableDestination:=wsSheet1.Range("A3"), TableName:="PivotTable", DefaultVersion:=xlPivotTableVersion10)

    This line now brings the error;

    Runtime Error 424

    Object Required

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    do you have an aversion to copy/paste?

    Please Login or Register  to view this content.
    note that second word is PT and third is PC

  9. #9
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    Set pt = pc.CreatePivotTable(TableDestination:=Sheet1.Range("A3"), TableName:="PivotTable", DefaultVersion:=xlPivotTableVersion10)

    Still same error.

  10. #10
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    what's the full code you are using and do you actually have a sheet whose codename (not tab name) is Sheet1?

  11. #11
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    Full Code;


    Please Login or Register  to view this content.
    Data is currently over 40k lines

    No coded sheet names, just the tab name for the data of 'data'
    Last edited by kenadams378; 05-15-2012 at 04:11 AM.

  12. #12
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    this line:
    Please Login or Register  to view this content.
    should be (as posted)
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    Thank you for all your help, it now says - Object Variable or With Block variable not set for this line;

    .ManualUpdate = True

  14. #14
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    I don't see how that is possible with the code as posted since pt was set in the previous line. (I assume you reran the code)

  15. #15
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    Yep re ran the code 2 or 3 times.

  16. #16
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    I just tested it to make sure and it runs fine for me so just to be sure can you copy and paste the current version of the code that you are running?

  17. #17
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    Please Login or Register  to view this content.
    Last edited by kenadams378; 05-15-2012 at 04:12 AM.

  18. #18
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    ah - typo this line:
    Please Login or Register  to view this content.
    should be
    Please Login or Register  to view this content.
    note change from R1A1 to R1C1 in the SourceData argument. strange you didn't get an error earlier in the code though.

  19. #19
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    Thanks for hihglihgting that.

    It's still not happy about this line;

    Please Login or Register  to view this content.
    I'm using Excel 2010, would it be an issue with differences in software?
    Last edited by kenadams378; 05-15-2012 at 04:12 AM.

  20. #20
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    no - that's what I tested on. sample workbook would be very useful now I reckon.

  21. #21
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    Sample attached, had to trim the data down to 5 lines as the spreadsheet is normal around 120mbSample.xls

  22. #22
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    works for me once I change the sheet name in the SourceData part from S29 to Data as in your sample workbook, and alter the DataPivotField part to:
    Please Login or Register  to view this content.

  23. #23
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    Can you send me the spreadsheet you have used with a completed version of the macro on it, i can then use this as the template to run the macro?

    I've still got issues with this line, that it doesn't like;

    Please Login or Register  to view this content.
    Last edited by kenadams378; 05-15-2012 at 04:13 AM.

  24. #24
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    see attached version of your file.
    Attached Files Attached Files

  25. #25
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    Many thanks for this, it works within the current spreadsheet i think the issue i had was trying to run the macro from a central summary sheet.

    The macro will need to be used monthly with different monthly data, do you know how i could use this macro as a central stand alone piece?

    Many thanks for all your help!

  26. #26
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    it depends on what you mean by different data.
    you can save the macro in a personal macro workbook or an add-in and run it from there.

  27. #27
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    The data will essentially be the same but for a different period and will be in a different excel sheet.

    Ideally a central document would have the macro in it to prompt for the file required to create the pivot table?

    I thought the coding at the beginning of the macro would do this?

  28. #28
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    the code at the start does prompt for a filename but you don't then use that anywhere in the code - you open a file that is specified in the code.

  29. #29
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    Is there a way to change it, so it opens the file that it prompts the user for?

  30. #30
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    yeah - use
    Please Login or Register  to view this content.
    instead of the fixed path you are using now.

  31. #31
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    How would this appear in the full code as there are numerous mentions of that coding;

    Please Login or Register  to view this content.
    Last edited by kenadams378; 05-15-2012 at 04:11 AM.

  32. #32
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    Please Login or Register  to view this content.
    should be
    Please Login or Register  to view this content.
    btw, I suggest you learn to use code tags before a moderator comes along.

  33. #33
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    Ah apologies, i tried that earlier using

    code[]
    &code[]/

    Does this not work?

  34. #34
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    Thanks for this!

    Using this change i get an error with the following line;

    Set pt = pc.CreatePivotTable(TableDestination:=wsPivot.Range("A3"), TableName:="PivotTable", DefaultVersion:=xlPivotTableVersion10)

  35. #35
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    what error? is the sheet name correct?

    tags are actually
    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code]

  36. #36
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    The error i now have is with the current line

    Please Login or Register  to view this content.
    The error is - Unable to set the number format property of the pivot field class

  37. #37
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    I'd just remove that line.

  38. #38
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    Spot on. That has all worked now.

    I was thinking last night, how could i add in the steps that open the source data then copy and paste it to another spreadsheet?

    So once i open the newFN, copy all the data in the sheet and paste it to another location?

  39. #39
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    that seems like a different question to me

  40. #40
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Current VBA Macro is slow. How can i speed up moving data from 1 sheet into a Pivot ta

    Apologies, i have started a new thread..

    Much apprecaite your help

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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