+ Reply to Thread
Results 1 to 8 of 8

Syntax for items inside and outside of a Pivot Table

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,065

    Syntax for items inside and outside of a Pivot Table

    Trying to automate a process, and getting stuck on defining things. I think I've spelled it out in my workbook, but here's the background:

    I start off creating a pivot via a macro. Got that part, no problem. Now I need to build formulas, labels, relative to items in the pivot, and I'm getting stymied by lack of syntax.
    • The Row of Headers, the items that go in the pivot ROWS area, what do I call that row in a macro?
    • The first cell outside (to the right of) that pivot, on that ROWS row, how do I call that?
    • The row above my ROWS row has a column with the name of "Projection". It's the last column of my pivot. So Row1, "Projection" column. How do I pinpoint that cell?
    • The cell two columns away from "JOURNAL_ID" but on the same row, or one column away from '(Multiple Items)", how do I deposit a value in that cell?
    • The formula in my first column to the right of my pivot has to take the average for all of my "2023_*" fields EXCEPT "2023_01". How do I do that formula?
    Sorry to have to come for help, but I'm humble enough to know when my poor brain just doesn't have the firepower I need.

    BTW, I would include my macro, but it currently only goes to completing the pivot, and that's where I get stuck. But "PT" means "Pivottable" all through it.
    Attached Files Attached Files
    I know I'm not stupid, but I suspect I'm a lot stupider than I think I am

  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
    48,488

    Re: Syntax for items inside and outside of a Pivot Table

    See: https://peltiertech.com/referencing-...ranges-in-vba/
    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
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,065

    Re: Syntax for items inside and outside of a Pivot Table

    TMS,
    Good tutorial, one I've bookmarked long ago. But I'm too dull to make it work for me. For instance, the code below selects the FY_AP part of my ROWS row, so 9 columns. But where I need to get is to the first non-pivot cell to the right of that range. Using "Offset(0, 1)." moves my entire selection to the right one column, but what I want is that specific cell. So instead of the below code,

    Please Login or Register  to view this content.
    I need something like
    Please Login or Register  to view this content.
    Still trying to figure out how to do the rest of it as well.

  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
    48,488

    Re: Syntax for items inside and outside of a Pivot Table

    Try Offset(0, 1, 1, 1)

  5. #5
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,065

    Re: Syntax for items inside and outside of a Pivot Table

    I tried it like this:
    Please Login or Register  to view this content.
    and got a Run-time error "450", Wrong number of arguments or invalid property assignment. I thought that would happen because everything I've read says the VBA Offset only has two parameters.

  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
    48,488

    Re: Syntax for items inside and outside of a Pivot Table

    Sorry, thinking of the worksheet function (which I rarely use).

    Maybe try .Offset(0, 1).Resize(1, 1) then.

  7. #7
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,065

    Re: Syntax for items inside and outside of a Pivot Table

    Using it like so
    Please Login or Register  to view this content.
    , the code selects J12, so right line, but wrong cell. Trying to hit Q12. Once I find that I think the headers and formulas can be done by defining that column and using offset.

  8. #8
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,065

    Re: Syntax for items inside and outside of a Pivot Table

    I can get it like this
    Please Login or Register  to view this content.
    , but the 8 in the Offset depends on how many months of expense there are.

    So going this route, I'd have to define a variable which is the count of "2023*" in the DataRange row, and add 1 to it.

    Seems like there should be an easier to way to say "First cell outside of the DataRange"

+ 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: 7
    Last Post: 02-27-2017, 07:41 AM
  2. Create a table/pivot table using different items items from a column
    By stevetton in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 09-28-2016, 10:30 PM
  3. [SOLVED] Median inside Pivot Table
    By MPatri in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-21-2016, 03:57 PM
  4. Filter pivot items using pivot items from another table
    By DKolev in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-16-2014, 08:49 PM
  5. Replies: 1
    Last Post: 09-03-2012, 10:03 PM
  6. Calculation inside pivot table
    By tkuia in forum Excel General
    Replies: 6
    Last Post: 04-12-2010, 05:47 AM
  7. Replies: 3
    Last Post: 08-16-2006, 09:50 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