+ Reply to Thread
Results 1 to 5 of 5

Dynamic formula in Pivot Table Data Source

  1. #1
    Registered User
    Join Date
    10-30-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    11

    Dynamic formula in Pivot Table Data Source

    I've been racking my brain on this for a while and can't seem to make it work (i'm not sure if it's possible). In simple terms, I would like a pivot table to refresh with the data source based on a specific cell which would be a dynamic named range.

    I pull data daily and name each worksheet based on the days date. i.e. for today, I would name the worksheet: "4.21"

    I have a "inputs" worksheet which includes a list of every range of every tab in column B:

    "4.20'!A1:L120"
    "4.21'!A1:L110"
    "4.22'!A1:L112"

    In the "inputs" worksheet, there is a specified cell that returns the last named range in column B. This cell is named "LatestDate" as a named range.

    I have a pivot table and would like to replace the "data source" using this "LatestDate" value. I tried using: indirect(LatestDate), however it returns an error saying I need at least 2 rows of data. The current data source for the pivot table is '4.22'!A1:L112, however, I can't seem to replace it with a dynamic formula incorporating the "LatestDate" named range...i'm not sure if this is possible?

    Appreciate anyone looking into this for me...

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,910

    Re: Dynamic formula in Pivot Table Data Source

    I recorded a macro and then "genericized" it and came up with the following. The code should be adaptable for your needs.
    - In cell B1, put the name of the sheet that contains the pivot table
    - In cell B2, put the name of the pivot table
    - In cell B3, put the name of the sheet containing the source data.

    The program will find the last row in the source data and it assumes the last column is column L.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,910

    Re: Dynamic formula in Pivot Table Data Source

    No sooner than I posted this that I thought of a non-VBA to do it. The attached workbook has some stuff left over from the previous post. I will leave it to you to clean up.

    This version works with a named dynamic range that uses INDIRECT.
    - Enter the sheet name that contains the source data in cell B3.
    - Cell B9 is a "helper cell" that gets the sheet part of needed formulas.
    - Cell B10 has the formula =COUNTA(INDIRECT(B9&"A:A")) - this formula goes to the source sheet and finds out how many rows there are.

    I then created a named dynamic range - Pivot_Source_Data =OFFSET(INDIRECT('Control Panel'!$B$9&"$A$1"),0,0,'Control Panel'!$B$10,12) and used this as the source for the pivot table. I suppose you could take the helper cells B9 and B10 and roll them into this formula.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    10-30-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    11

    Thumbs up Re: Dynamic formula in Pivot Table Data Source

    dflak - absolute legend. i used the non-vba version and it works like magic - incredibly simple. i couldn't for the life of me figure out how to write a formula that the pivot table named range would accept.

    thank you again!

  5. #5
    Registered User
    Join Date
    06-07-2016
    Location
    argentina
    MS-Off Ver
    2013
    Posts
    1

    Re: Dynamic formula in Pivot Table Data Source

    DFlak, this is insane indeed, you're a genius

+ 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. Formula to return Pivot Table data source
    By xtinct2 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-24-2016, 11:12 AM
  2. Replies: 0
    Last Post: 01-06-2016, 07:00 AM
  3. Change Pivot Table Data Source based on Dynamic Range
    By hamidxa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-16-2014, 04:46 PM
  4. Dynamic worksheet source for Pivot Table
    By spokospoko in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 07-01-2014, 05:12 PM
  5. Replies: 4
    Last Post: 06-25-2012, 03:25 PM
  6. Update Pivot table using a dynamic range for source data
    By Carl Thompson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-02-2011, 08:20 AM
  7. [SOLVED] Pivot Table With Dynamic Range Source
    By S Jackson in forum Excel General
    Replies: 4
    Last Post: 08-31-2005, 11:05 AM

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