+ Reply to Thread
Results 1 to 8 of 8

Pivot Table - Looping Through Pivot Fields

  1. #1
    Registered User
    Join Date
    10-06-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Question Pivot Table - Looping Through Pivot Fields

    Hey Guy and Dolls,

    It’s my first time here, so bear with me if I haven't done something I was suppose to do while posting. Any feedback would be greatly appreciated.

    First off, I would like to thank the person/people who created this site so people like me can ask questions. Also I would like to thank the volunteers that use their spare time (or sometimes work time ) to answer my questions. I hope that in the future I will be among these warriors of people.

    Ok my question, it’s in regards to pivot table pivot fields.

    I have created a macro that will create a pivot table in a specified worksheet and fill in the row and data fields. The problem is I need the data field to include multiple pivot fields that meet a specified criteria.

    Is it possible the macro could loop through all available pivot fields, looking for the word 'Points' and then putting the matching pivot field into the data field?

    To explain in more detail I have attached a sample workbook with my existing macro and the following worksheets:
    1. Data - Contains the data that the pivot table uses. This is generic.
    2. Pivot - This is where the macro creates the pivot table. This is generic.
    3. CorrectPivot - This shows a pivot table in which I would like the macro to create.

    I hope I was as clear as possible.

    Kind Regards

    Mini12
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    09-18-2008
    Location
    india
    Posts
    158

    Re: Pivot Table - Looping Through Pivot Fields

    Hi Mini,

    Please find attached.

    Regards,
    Shekar Goud.
    Attached Files Attached Files

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Pivot Table - Looping Through Pivot Fields

    Mini12,

    I think in fact you want something a little more dynamic - ie code along the lines of:

    Please Login or Register  to view this content.
    The above will create the PT and iterate all fields adding any containing " Points" to the Data Field section.

    Note in the above for testing I altered the destination of the PT to be a new sheet created at run-time (change as necessary).

  4. #4
    Registered User
    Join Date
    10-06-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Question Re: Pivot Table - Looping Through Pivot Fields

    Hey Shekar,

    Thanks for answering the question, the only problem is I cannot add the pivot fields individually. This is because I am trying to make this code universal where it can be used on multiple workbooks with many different number of 'Points' fields.

    For example, sample1.xls has 2 fields that has 'Points' in the field name, but sample2.xls has 12 fields with 'Points' in the field name.

    So to make it universal I need the code to loop through all pivot fields looking for the word 'Points' within the fieldname and then add it to the data field.

    I have tried to create this code but failed, this is how far I got:

    Please Login or Register  to view this content.
    Does anyone have any ideas?

    Kind Regards

    mini12

  5. #5
    Registered User
    Join Date
    10-06-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Thumbs up Re: Pivot Table - Looping Through Pivot Fields

    Wow that was fast, got a reply before I posted a reply.

    Is there mindreaders here?

  6. #6
    Registered User
    Join Date
    10-06-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Lightbulb Re: Pivot Table - Looping Through Pivot Fields

    Thanks, DonkeyOte & shekar goud, you were great help.

    I can't believe I was that close to solving the solution myself. Thank you DonkeyOte for filling the missing pieces of the puzzle.

    I just then made three minor adjustments, which are as follows:

    Please Login or Register  to view this content.
    Bingo it works!

    Problem solved.

    Kind Regards

    mini12

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,972

    Re: Pivot Table - Looping Through Pivot Fields

    Just FYI, there is no need to use a separate function to convert the name to upper case, since InStr has an argument to specify whether the comparison should be case sensitive:
    Please Login or Register  to view this content.
    FWIW.
    Everyone who confuses correlation and causation ends up dead.

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Pivot Table - Looping Through Pivot Fields

    Thanks R.... takes me another step further from a smarta$$ and one closer to a dumba$$

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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