+ Reply to Thread
Results 1 to 10 of 10

VBA and pivot table

  1. #1
    Registered User
    Join Date
    02-23-2011
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    33

    VBA and pivot table

    Hi,

    Working on a macro to create a from a database.
    - After I made the pivot table on a new sheet I want to change the name of the sheet. How do I add this?
    - Right now the macro stops at TableDestination row in the code, why ?
    - Will the names I gave for the pivotfields (1,5,6) ensure that these columns are added from the raw data ? (the names of the column is the raw data is not 1,5,6 but Supplier, source and so on).

    Please Login or Register  to view this content.

    Appreciate your help!
    Last edited by thylander; 03-17-2011 at 04:28 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,510

    Re: VBA and pivot table

    It would be helpful, at least for me, if you posted a sample workbook containing some typical data (not necessarily live data) which could be used to test your code.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    02-23-2011
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    33

    Re: VBA and pivot table

    Attached a example file,

    Another question, how do i remove the "count of" and "Sum of" in the column headers?
    Attached Files Attached Files
    Last edited by thylander; 03-16-2011 at 05:18 AM. Reason: Added question

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,510

    Re: VBA and pivot table

    It's probably easier to set at reference to the new worksheet when you create it and change the name at the same time. See the code below.

    The code works fine for me with Excel 2007. And yes, it picks up the names of the fields.

    Regards

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-23-2011
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    33

    Re: VBA and pivot table

    Well, that worked fine. Just didn't get the name function to work properly but I used

    ActiveSheet.Name instead.

    Just a follow up question, if I want to get rid of the grand total in the bottom and remove the "count of" and "sum of" in the column header, how do I do that?

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,510

    Re: VBA and pivot table

    To remove the Grand Total line, add ".ColumnGrand = False":

    Please Login or Register  to view this content.


    I'm not sure how you get rid of the "Sum of" and "Count of". Probably not difficult, I just do not know how to do it.


    Regards

  7. #7
    Registered User
    Join Date
    02-23-2011
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    33

    Re: VBA and pivot table

    Thx for the help,

    Found a piece of code that I think will work the only issue is that the name changes in the header every time.

    Please Login or Register  to view this content.
    Only problem is how i modify it so it just removes the presceding "sum of" or "Count of" because the column header changes.

    Anyone got any ideas ?
    Last edited by thylander; 03-17-2011 at 05:55 AM.

  8. #8
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: VBA and pivot table

    Hi

    At these 2 Dim items at the beginning of your code, than insert the following code immeditaley after your .DisplayFieldCaptions = False

    Please Login or Register  to view this content.
    You would also benefit in speed if you set
    Application.ScreenUpdating = False
    at the beginning of your code, and back to true before End sub
    --
    Regards
    Roger Govier
    Microsoft Excel MVP

  9. #9
    Registered User
    Join Date
    02-23-2011
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    33

    Re: VBA and pivot table

    Thanks alot Roger,

    Was looking around for different options but this one worked out great!

    By anychance do you know how to change so instead of using count of it uses Sum as function ?


    BR

  10. #10
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: VBA and pivot table

    Hi

    Please Login or Register  to view this content.

+ 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