+ Reply to Thread
Results 1 to 12 of 12

Problem with Macro creating Pivot Table

  1. #1
    Forum Contributor
    Join Date
    05-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    186

    Problem with Macro creating Pivot Table

    So I am just venturing into making some more macros that aren't completly routine to me. Here is the code I have so far.

    Please Login or Register  to view this content.
    I am trying to get it to simply take the data on the first worksheet and create a simple pivot table on an already existing table. I am getting an error with the first 4 lines.

  2. #2
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Problem with Macro creating Pivot Table

    on an already existing table? is there a pivot table already in place on Report 8 Pivot? if so you can just refresh the table in the macro (no create one)
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Problem with Macro creating Pivot Table

    Hi smls
    No way to test but you can try this
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Forum Contributor
    Join Date
    05-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    186

    Re: Problem with Macro creating Pivot Table

    when I rerun the macro I get an error. Where do I put the command in the macro to refresh?

  5. #5
    Forum Contributor
    Join Date
    05-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    186

    Re: Problem with Macro creating Pivot Table

    I can't really upload the workbook because it has confidential information in it otherwise I would. I tried copying and pasting jaslake's code but got an error at
    Please Login or Register  to view this content.

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Problem with Macro creating Pivot Table

    Hi smls
    Don't know...try changing
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

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

    Re: Problem with Macro creating Pivot Table

    if you want to refresh a pivot table you already created, you don't need a macro-just right-click it and choose refresh. :-)
    btw in your original code you have spaces in the sheet names so you have to enclose the name in single quotes, and the tabledestination argument should only be one cell.
    Josie

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

  8. #8
    Forum Contributor
    Join Date
    05-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    186

    Re: Problem with Macro creating Pivot Table

    Thnaks for the feedback
    Please Login or Register  to view this content.
    Did you mean to change the " " to ' '? I tried that but now the debugger stops right there. I am probably doing something wrong but I am just not used to debugging again yet. Its been like 6 years and that was only back with html and java when I actually knew them lol. I'm trying to kinda relearn this from scratch.

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

    Re: Problem with Macro creating Pivot Table

    no-I was referring to your original code
    Please Login or Register  to view this content.
    not a good idea to use entire columns though so I'd use
    Please Login or Register  to view this content.
    I prefer using variables for each step as it's easier to debug and then you can reuse the pt variable when adding all the fields and formatting the pivot table.

  10. #10
    Forum Contributor
    Join Date
    05-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    186

    Re: Problem with Macro creating Pivot Table

    Thanks for the help everyone, I appreciate you taking the time to help me. I think I am just going to throw in the towel with this one for now and maybe try again another time.

  11. #11
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Problem with Macro creating Pivot Table

    @ josephP,

    using macros to refresh pivot tables is sometimes really very helpful. For instance if the user is altering the contents of a worksheet using a macro and another sheet feeds multiple pivot table/charts from that altered data, refreshing the pivots for them is nice. They don't know what is happening, but every time they access the sheet the tables/charts are accurate

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

    Re: Problem with Macro creating Pivot Table

    agreed though I prefer event code for that (if I can't rely on a user to refresh a pivot normally I ain't going to rely on him pressing any other button instead!).

+ 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