+ Reply to Thread
Results 1 to 10 of 10

Error in pivot table macro

  1. #1
    Registered User
    Join Date
    11-08-2022
    Location
    Davenport, IA
    MS-Off Ver
    MS 360
    Posts
    15

    Angry Error in pivot table macro

    Hello,

    I am having difficulty placing a pivot table on an existing worksheet, it's when I come to the step of declaring what PSheet is referring to and what Dsheet is referring to.

    Attached is workbook for better reference:
    My main data is being pulled from Sheet1 by a formula (which I need to add to macro)
    EFT worksheet is where the pivot table data will be pulled from
    EFTPivot worksheet is where I want the pivot table to populate
    Payment worksheet is what I want my end result to look like.

    But my issue, at least right now when trying to run the macro is when I'm identifying sheet names.
    Attached Files Attached Files

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,209

    Re: Error in pivot table macro

    Hi Rebecca,

    I believe the problem is with your Sheet CodeNames. I think the errors are because you have duplicate sheet codenames and tab words. See the attached where I've changed the Sheet CodeNames and use .CurrentRegion to save some steps. I didn't dig through your whole code just the top parts.

    Clinic Macro VBA Help Sheet CodeNames Wrong.xlsm

    https://www.youtube.com/watch?v=MU3e6iqc0Rk
    I've learned a lot of good vba from Paul Kelly. He has really improved my VBA. You should watch many of his other videos.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    11-08-2022
    Location
    Davenport, IA
    MS-Off Ver
    MS 360
    Posts
    15

    Re: Error in pivot table macro

    Thank you for a quick reply.

    I've updated the issue and it now gets to creating the first pivot table row command and stops. Do I need to remove "End With"?
    Attached Files Attached Files

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,209

    Re: Error in pivot table macro

    Hi Rebecca,

    The "End With" won't get you where you need to go. I'd have to turn on the VBA recorder and build what you show on your payment sheet. Then turn off the recording and look at the VBA code it built. Then trim and hack the recorded code to look like what you want. I'll play with that for a few minutes and see what happens. In the meantime watch: https://www.youtube.com/watch?v=dRW5O-7FTBU
    I'm no expert with VBA to Pivot Tables but just know how to learn...

  5. #5
    Registered User
    Join Date
    11-08-2022
    Location
    Davenport, IA
    MS-Off Ver
    MS 360
    Posts
    15

    Re: Error in pivot table macro

    I am no expert either, I went to here excelchamps . com/blog/vba-to-create-pivot-table/ and found this premade macro for a pivot table. Just amended where I needed, ran it and came up with the first error. I then did your recommendation in recording a macro, which really only works one time as it doesn't specify variables before hand.

  6. #6
    Registered User
    Join Date
    11-08-2022
    Location
    Davenport, IA
    MS-Off Ver
    MS 360
    Posts
    15

    Re: Error in pivot table macro

    I am no expert either, I went to excelchamps and searched vba-to-create-pivot-table and found this premade macro for a pivot table. Just amended where I needed, ran it and came up with the first error. I then did your recommendation in recording a macro, which really only works one time as it doesn't specify variables before hand.

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

    Re: Error in pivot table macro

    Rebecca

    Which sheet has the raw data on it?

    Are you trying to create multiple pivot tables?

    In the workbook you attached, which pivot table is the one the current code is creating?
    If posting code please use code tags, see here.

  8. #8
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,209

    Re: Error in pivot table macro

    Hi Rebecca,

    I recorded a macro to build your Pivot Table on the Pivot sheet. Then I trimmed what didn't seem needed and made a loop for pivotfields. See it in the Module2. If your data isn't what is in your example then the names of the pivot rows will be all wrong. I hope this helps.
    Clinic Macro Again 3.xlsm

  9. #9
    Registered User
    Join Date
    11-08-2022
    Location
    Davenport, IA
    MS-Off Ver
    MS 360
    Posts
    15

    Re: Error in pivot table macro

    Hello,

    Thank you for building that! Now just copying this macro into what I'm using it in, it gets caught up on ShtPivot.UsedRange.ClearContents. So I simply tried to remove it and it creates the blank pivot table on EFTPivot tab then gets hung up on ShtPivot.PivotTables("PivotTable1").RowAxisLayout xlTabularRow.

    The only difference between the workbook on this thread and what I'm using is its full with real data.

  10. #10
    Registered User
    Join Date
    11-08-2022
    Location
    Davenport, IA
    MS-Off Ver
    MS 360
    Posts
    15

    Re: Error in pivot table macro

    Hello,

    The sheet with raw data is "Sheet1".
    Eventually I do want multiple pivot tables, but broken out on different tabs. So my current goal, which is uploaded, is to breakout the data on Sheet1 by using the filter formula turning that into a table then running a pivot table of "EFTTable" to show up on EFTPivot tab.
    The next goal is to have the "Payment" tab pull the data from "Sheet1" using the filter formula, setting it up by Table then creating another pivot table on "PaymentPivot" which is not included on the example uploaded.

    The last question I'm not understanding.

+ 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. Running a Macro - Pivot Table Error
    By AndreO4 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-21-2019, 07:31 AM
  2. Pivot Table Macro Error
    By Remotruker in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-12-2018, 03:58 PM
  3. Pivot Table Macro Error
    By goranLC in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-27-2017, 12:28 PM
  4. [SOLVED] Pivot Table Filter Macro Error
    By kibbles in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-28-2014, 03:19 PM
  5. Pivot Table Macro Error
    By NDRYNWA in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-01-2013, 09:04 AM
  6. Runtime error 438 in Pivot table macro
    By DavidBW in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 01-10-2012, 11:12 AM
  7. macro error on Pivot Table refresh
    By mheinmiller in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-22-2008, 02:23 PM

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