+ Reply to Thread
Results 1 to 10 of 10

VBA: Group Pivot Dates By Year

  1. #1
    Registered User
    Join Date
    10-27-2012
    Location
    Uk
    MS-Off Ver
    Excel 2010
    Posts
    98

    Question VBA: Group Pivot Dates By Year

    Hi All,

    From everything I've read on this forum and other sites, the below code should work, but I'm getting a runtime error 1004 - Group method of range class failed?

    Please Login or Register  to view this content.
    Any advice appreciated
    All the best
    V
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    10-27-2012
    Location
    Uk
    MS-Off Ver
    Excel 2010
    Posts
    98

    Re: VBA: Group Pivot Dates By Year

    Oh golly this must be a tricksy one I think

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,755

    Re: VBA: Group Pivot Dates By Year

    I did a record Macro to group the dates and this is what it provided. Compare the results to yours

    Please Login or Register  to view this content.

    The difference is in the last True which the recorded Macro indicates is False.

    Excel 2016 (Windows) 32 bit
    H
    I
    J
    3
    Count of Fruit Column Labels
    4
    Row Labels Oct Grand Total
    5
    apples
    5
    5
    6
    grapes
    4
    4
    7
    oranges
    4
    4
    8
    Grand Total
    13
    13
    Sheet: Sheet1
    Last edited by alansidman; 09-20-2020 at 09:46 AM.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Registered User
    Join Date
    10-27-2012
    Location
    Uk
    MS-Off Ver
    Excel 2010
    Posts
    98

    Re: VBA: Group Pivot Dates By Year

    Hi Alansidman

    Thanks for the reply

    I do actually want the last one to be True, so that it groups by year
    I tried adding the select statement shown in your code above, and sure enough it worked

    Please Login or Register  to view this content.
    But I really don't want to use a cell reference if I can help it.
    Otherwise if the user adds rows above the pivot table the cell reference well change and the macro will no longer work

    Is there any way to group a pivot by year without specifying a cell reference?

    All the best
    V

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,755

    Re: VBA: Group Pivot Dates By Year

    How about giving it a range name and referring to that range in your script?

  6. #6
    Registered User
    Join Date
    10-27-2012
    Location
    Uk
    MS-Off Ver
    Excel 2010
    Posts
    98

    Re: VBA: Group Pivot Dates By Year

    I'm not sure I follow?

    The pivot table has a name. Is it possible to reference that?

  7. #7
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: VBA: Group Pivot Dates By Year

    Hi V,

    Try this ...
    Please Login or Register  to view this content.
    If I was able to help, you can thank me by clicking the * Add Reputation under my user name

  8. #8
    Registered User
    Join Date
    10-27-2012
    Location
    Uk
    MS-Off Ver
    Excel 2010
    Posts
    98

    Re: VBA: Group Pivot Dates By Year

    I was holding my breath as I stepped through that sub

    Thank you so much! It works perfectly

  9. #9
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: VBA: Group Pivot Dates By Year

    Glad to help

    If the provided solution takes care of your original question, please take a moment & mark this thread as [SOLVED] from the Thread Tools above your first post & consider * Add Reputation to those who have helped by clicking the star icon under their usernames

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,174

    Re: VBA: Group Pivot Dates By Year

    Administrative Note:

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.

    (Note: this requirement is not optional. No help to be offered until the link is provided.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

+ 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. Year on year pivot chart when dates go horizontal?
    By mra1984 in forum Excel Charting & Pivots
    Replies: 9
    Last Post: 04-25-2018, 10:44 AM
  2. [SOLVED] Group multiple dates in PT by year and month
    By bristly in forum Excel Charting & Pivots
    Replies: 6
    Last Post: 10-12-2015, 11:34 AM
  3. How to get Year from GROUP Pivot Table
    By dluhut in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-18-2014, 12:22 PM
  4. [SOLVED] Extracting dates of group of occurrences over year period
    By Cygnet in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-14-2014, 07:06 AM
  5. Group dates by month & year formt
    By vamshi57 in forum Excel General
    Replies: 5
    Last Post: 04-14-2014, 07:38 PM
  6. [SOLVED] run time error creating pivot table and group dates by year and month
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-15-2013, 07:25 AM
  7. Pivot Group Dates - how to remove start and end dates from table
    By markoloughlin in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 08-21-2012, 04:19 AM

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