+ Reply to Thread
Results 1 to 19 of 19

Pivot table using vba

  1. #1
    Forum Contributor
    Join Date
    08-22-2013
    Location
    columbus,oh
    MS-Off Ver
    Office 365
    Posts
    190

    Pivot table using vba

    I am trying to do a pivot table using VBA.
    I have uploaded a sample data sheet and a sample output view.
    The only change that I want in the output is I want them to be interleaved.
    So I want Units 2014 the Units 2015 then Unit Diff from 2014 ,Unit Diff from 2015 and then % of sales units 2014,% of sales units 2015.
    I wasn't able to get it that way in this view.
    Also the data set will be much larger so essentially it needs to find the last row on the FY2015 Data sheet and use that as Pivot Data.
    I did try to start the code in module1 but am stuck.

    Thank you !
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Pivot table using vba

    try similar code
    Please Login or Register  to view this content.
    "No xadrez nem sempre a menor dist?ncia entre dois pontos ? uma linha reta" G. Kasparov.

    If your problem is solved, please say so clearly, and mark your thread as Solved: Click the Edit button on your first post in the thread, Click Go Advanced, select b from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Edit button will not appear -- ask a moderator to mark it.

  3. #3
    Forum Contributor
    Join Date
    08-22-2013
    Location
    columbus,oh
    MS-Off Ver
    Office 365
    Posts
    190

    Re: Pivot table using vba

    Thank you !
    This helps a lot but i still don't know how to do the difference from YOY like how i laid out in the sample pivot that I did using VBA.
    Thoughts?

  4. #4
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Pivot table using vba

    Do you try record Macros?

  5. #5
    Forum Contributor
    Join Date
    08-22-2013
    Location
    columbus,oh
    MS-Off Ver
    Office 365
    Posts
    190

    Re: Pivot table using vba

    No I couldnt get it to work .can someone help?

  6. #6
    Forum Contributor
    Join Date
    08-22-2013
    Location
    columbus,oh
    MS-Off Ver
    Office 365
    Posts
    190

    Pivot table using vba

    I am trying to do a pivot table using VBA.
    I have uploaded a sample data sheet and a sample output view.
    The only change that I want in the output is I want them to be interleaved.
    So I want Units 2014 the Units 2015 then Unit Diff from 2014 ,Unit Diff from 2015 and then % of sales units 2014,% of sales units 2015.
    I wasn't able to get it that way in this view.
    Also the data set will be much larger so essentially it needs to find the last row on the FY2015 Data sheet and use that as Pivot Data.
    I did try to start the code in module1 but am stuck.

    Thank you ! Sample report.xlsm

  7. #7
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Pivot table using vba

    Does this help, as a starting point?
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  8. #8
    Forum Contributor
    Join Date
    08-22-2013
    Location
    columbus,oh
    MS-Off Ver
    Office 365
    Posts
    190

    Re: Pivot table using vba

    Thank you ! this helps a lot but when I run the code and it comes to creating the Pivot Cache and it bombs out..thoughts?

  9. #9
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Pivot table using vba

    It will error if you already have a pivotcache in the workbook based on that data range. Try deleting the existing pivotcache first.

  10. #10
    Forum Contributor
    Join Date
    08-22-2013
    Location
    columbus,oh
    MS-Off Ver
    Office 365
    Posts
    190

    Re: Pivot table using vba

    how do I delete existing Pivot cache?

  11. #11
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Pivot table using vba

    For manual testing, simply manually delete the pivot table in worksheet "Pivots".

    Here, look at my attachment - try running the SampleReport macro.
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    08-22-2013
    Location
    columbus,oh
    MS-Off Ver
    Office 365
    Posts
    190

    Re: Pivot table using vba

    It works in the sample report but for some reason not when I plunk it in my workbook.I am going to try and play with it a bit and see why it doesnt work since this pivot is a call function from a different sub.Thanks for now.
    I will post if I have any more questions.
    Thanks!

  13. #13
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Pivot table using vba

    Merged duplicate threads.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  14. #14
    Forum Contributor
    Join Date
    08-22-2013
    Location
    columbus,oh
    MS-Off Ver
    Office 365
    Posts
    190

    Re: Pivot table using vba

    OK So I have been poking around it and figured out that the Pivot Cache crashed since my data is >65000 lines.
    Is there anyway for the pivot cache to accept data that is >65000 lines?

    Thanks!

  15. #15
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Pivot table using vba

    Should cope with >65k rows in Excel 2010, no problems. I have pivot caches on 100k+ row data sources...

  16. #16
    Forum Contributor
    Join Date
    08-22-2013
    Location
    columbus,oh
    MS-Off Ver
    Office 365
    Posts
    190

    Re: Pivot table using vba

    Hi Olly,
    thanks for the reply.
    If I reduce the dataset to say like 60K rows then it creates the pivot but not for>65K rows.Thoughts?

  17. #17
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Pivot table using vba

    Is the file saved in 97-2003 (.xls) format? Try creating a new workbook in 2007+ format (.xlsm) and see how it works.

  18. #18
    Forum Contributor
    Join Date
    08-22-2013
    Location
    columbus,oh
    MS-Off Ver
    Office 365
    Posts
    190

    Re: Pivot table using vba

    it is saved as Excel 2010 Xlsm.
    I have tried saving it diff file /diff module but same result.

  19. #19
    Forum Contributor
    Join Date
    08-22-2013
    Location
    columbus,oh
    MS-Off Ver
    Office 365
    Posts
    190

    Re: Pivot table using vba

    Thanks for you help Olly.I put the PC range address slightly differently and it worked where instead of current region it refers to :

    Thank you !!

    HTML Code: 

+ 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. Replies: 6
    Last Post: 07-31-2014, 12:56 PM
  2. Collapse/Expand - Pivot table Fields - Need equivalent option in Excel VBA Pivot table
    By ragavendraph in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-07-2012, 03:00 PM
  3. Replies: 1
    Last Post: 06-22-2010, 09:10 AM
  4. Replies: 1
    Last Post: 06-20-2010, 04:00 AM
  5. Return pivot table range...not the data table, the PIVOT TABLE!
    By Air_Cooled_Nut in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-26-2008, 01:07 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