+ Reply to Thread
Results 1 to 11 of 11

MARCO VBA Pivot table referencing

  1. #1
    Registered User
    Join Date
    05-24-2021
    Location
    Atlanta, Georgia
    MS-Off Ver
    Microsoft Office Professional Plus 2019
    Posts
    5

    MARCO VBA Pivot table referencing

    Hello,

    Hello! I'm working on an assignment and I'm a little stuck. I'd like it to be in VBA so I can run a macro when there are more serial numbers and dates.

    There are 2 pivot tables. The first pivot table shows the error dates and how many error dates are created per a day pertaining to each serial number.
    The second pivot table show the review dates and how many reviews were held per a date for each serial number.

    I need a formula that will allow me to fill out column R and Column S. I need to find the sum of the count of errors in the First pivot table "Error_Count" per each date created per each Serial Number in the pivot table according the range of Dates in the Sum_Errors table and output the sum in the table.

    For instance, R2 should be the sum of Count of Error_Dates (found in Column E) between the dates listed in P2 and O2 (2/11/20 - 3/11/20). The date won't always match but it has to be in-between the date range.
    S2 should be the sum of Count of Error_Dates between the dates listed in O2 and Q2 (3/11/20-4/11/20). Both R2 and S2 refer to serial number in M2.

    All the tables will have many more lines and dates. So, I'm trying very hard to think of some code that will help me count the errors between dates.

    Thank you!!! I'd really appreciate the help.
    Attached Files Attached Files

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: MARCO VBA Pivot table referencing

    Hi Miska and welcome to the forum,

    The closest I can come to your problem, without VBA is to group by date and set the number of days. See the attached and the new pivot table as an example.
    Error and Review Sum Group by 7 days.xlsm
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    05-24-2021
    Location
    Atlanta, Georgia
    MS-Off Ver
    Microsoft Office Professional Plus 2019
    Posts
    5

    Re: MARCO VBA Pivot table referencing

    That's basically what I had already. Just not specific enough, but thank you very much!

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: MARCO VBA Pivot table referencing

    I read your PM but the file will not open on my system. I can only open it with all events disabled and even if I save it under a new name with or without macros it won't open.
    Sorry for that, not much I can do without a working file (and the way you've set it up)
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  5. #5
    Registered User
    Join Date
    05-24-2021
    Location
    Atlanta, Georgia
    MS-Off Ver
    Microsoft Office Professional Plus 2019
    Posts
    5

    Re: MARCO VBA Pivot table referencing

    Hi Keebellah,

    I've attached it again. Hopefully it works!
    Attached Files Attached Files

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,908

    Re: MARCO VBA Pivot table referencing

    I think you could do this with GETPIVOTDATA and INDIRECT. It looks like you are excluding both start and end dates - is that accurate?
    Rory

  7. #7
    Registered User
    Join Date
    05-24-2021
    Location
    Atlanta, Georgia
    MS-Off Ver
    Microsoft Office Professional Plus 2019
    Posts
    5

    Re: MARCO VBA Pivot table referencing

    I'm trying to find the sum of the errors 1 month before the serial number's first review date and 1 month after the serial number's first review date. GETPIVOTDATA and INDIREC could work, but after looking it up I am so confused to how to even begin it. Not sure how I can have it work for each serial number?

  8. #8
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,908

    Re: MARCO VBA Pivot table referencing

    =SUM(IFERROR(GETPIVOTDATA("Error_Date",$D$1,"Serial_Number",2195550432,"Error_Date",ROW(INDIRECT(P2&":"&O2))),0))

    as an array formula will add the counts for all the dates from P2 to O2, for example.

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: MARCO VBA Pivot table referencing

    Problem seemed was not the file, Excel hung up on me somewhere in the background, killed the process and could open it again

  10. #10
    Registered User
    Join Date
    05-24-2021
    Location
    Atlanta, Georgia
    MS-Off Ver
    Microsoft Office Professional Plus 2019
    Posts
    5

    Re: MARCO VBA Pivot table referencing

    Thank you Rorya for the help! I do have a question is the Error_Date referring to the table name or the column header?
    =SUM(IFERROR(GETPIVOTDATA("Error_Date",$D$1,"Serial_Number",2195550432,"Error_Date",ROW(INDIRECT(P2&":"&O2))),0))

  11. #11
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,908

    Re: MARCO VBA Pivot table referencing

    It's the field name in the pivot table

+ 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: 19
    Last Post: 04-04-2016, 02:58 PM
  2. [SOLVED] Marco for pivot table like fuctions. Subtotal column C, based on column B criteria.
    By RobertOHare in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-09-2013, 02:57 PM
  3. Marco for copy data from pivot table
    By ronlau123 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-02-2011, 04:21 PM
  4. Excel 2007 : Referencing a Pivot Table
    By campanaro in forum Excel General
    Replies: 0
    Last Post: 07-14-2010, 01:07 PM
  5. marco for a pivot table and expansion
    By Macro for a Pivot Table in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-23-2005, 02:55 PM
  6. Pivot table marco problem!
    By matthewwookie in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-26-2005, 04:31 AM
  7. Marco: Pivot Table
    By Tim in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2005, 12:06 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