+ Reply to Thread
Results 1 to 19 of 19

Creating a Pivot Table based off an ever changing range...

  1. #1
    Registered User
    Join Date
    09-12-2014
    Location
    Morrisville, NC
    MS-Off Ver
    2013
    Posts
    40

    Creating a Pivot Table based off an ever changing range...

    I am building a macro to create a pivot table based off a range of data, however this range could change from day to day (ie sometimes more rows, sometimes less, but always the same number of columns).

    The macro I built uses a specific range, but I would like the macro to "select all" data in the workbook instead to create the pivot table. I noticed if I have blank rows in the range, it messes up the pivot table. Is there a way to have the code always select all information in the worksheet rather than a specific range of cells?

    Does this make sense?

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Creating a Pivot Table based off an ever changing range...

    instead of using VBA use dynamic named ranges with offset and Counta.

    Anytime I think I MIGHT update a file or the data, I create a named range called PivotDATA. I make use the following to make a dynamic named range with that.

    I select the data and hit INSERT Pivot, and instead of leaving the hardcoded range, I type in PivotDATA.


    Give me a second to make an example.
    Last edited by mikeTRON; 09-16-2014 at 02:42 PM.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Registered User
    Join Date
    09-12-2014
    Location
    Morrisville, NC
    MS-Off Ver
    2013
    Posts
    40

    Re: Creating a Pivot Table based off an ever changing range...

    How do I do that?

  4. #4
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Creating a Pivot Table based off an ever changing range...

    So the dynamic range works like this

    Please Login or Register  to view this content.
    It starts at cell A1
    Offsets 0 rows and 0 columns
    counts how many cells are used in column A then goes down that many rows
    counts how many cells are used in row 1 then goes to the right that number of columns

    SO if you want, you can FIX the number of columns with a static number or you can use the COUNTA method.
    Also, be aware if you type something in row 1 outside of the data, it will count it and add a row, and the same thing goes for adding anything in column A

    Try adding a few more full columns of headers and data
    Try adding more rows of data
    The PivotDATA named range will capture that dynamically.

    To test it, type the name PivotData into the named range area to the left of the formula bar.


    DynamicNamedRange.xlsx


    Obviously if you WANT to use VBA, you can easily do that as well.

  5. #5
    Registered User
    Join Date
    09-12-2014
    Location
    Morrisville, NC
    MS-Off Ver
    2013
    Posts
    40

    Re: Creating a Pivot Table based off an ever changing range...

    Thanks for your help. I found this in my searches, and it seems to work just fine selecting the cells I want, and it will change every time. Now how do I use this range in my pivot table?

    Please Login or Register  to view this content.
    I noticed that there is a range in the pivot table code, so I deleted it and changed it with the rngTemp name, but got errors. isn't this ranged named rngTemp or do I need to do something else like actually name the range and use that range of cells name for the pivot table?

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Creating a Pivot Table based off an ever changing range...

    Did you even try my method?

  7. #7
    Registered User
    Join Date
    09-12-2014
    Location
    Morrisville, NC
    MS-Off Ver
    2013
    Posts
    40

    Re: Creating a Pivot Table based off an ever changing range...

    One side note, I went ahead and tried to set up the macro with a named range, however it set up a specific range of cells (ie: A2:D375) as the range. I know if I have another day where there's more or less information, it will either miss it or screw up the pivot table. Any suggestions?

  8. #8
    Registered User
    Join Date
    09-12-2014
    Location
    Morrisville, NC
    MS-Off Ver
    2013
    Posts
    40

    Re: Creating a Pivot Table based off an ever changing range...

    Not yet Mike. I found that code and was typing everything up while you were typing your response, so I didn't see it until after I had finished my post. I'm giving it a go now.

  9. #9
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Creating a Pivot Table based off an ever changing range...

    Alright, let me know if you have any questions or if you still prefer to use a named range and/or VBA.

  10. #10
    Registered User
    Join Date
    09-12-2014
    Location
    Morrisville, NC
    MS-Off Ver
    2013
    Posts
    40

    Re: Creating a Pivot Table based off an ever changing range...

    Hey Mike,

    I'm not sure this will work for what I'm trying to do. Let me try to explain. We have a list of inventory items that are currently on back order. I've set up the spreadsheet using VBA so that it only shows orders needing inventory 45 days into the future, so as you can see, it will change from day to day.

    So there is one inventory line item with their quantity for each order. Therefore there can be and are multiple line items of the same inventory part number and quantity. The pivot table shows me these part numbers and the total quantity of all the line items.

    This information will then be drawn into another spreadsheet using a VBA macro, so I need to do all of this within VBA.

    Any suggestions?

  11. #11
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: Creating a Pivot Table based off an ever changing range...

    Quote Originally Posted by Joven76 View Post
    Hey Mike,

    I'm not sure this will work for what I'm trying to do. Let me try to explain. We have a list of inventory items that are currently on back order. I've set up the spreadsheet using VBA so that it only shows orders needing inventory 45 days into the future, so as you can see, it will change from day to day.

    So there is one inventory line item with their quantity for each order. Therefore there can be and are multiple line items of the same inventory part number and quantity. The pivot table shows me these part numbers and the total quantity of all the line items.

    This information will then be drawn into another spreadsheet using a VBA macro, so I need to do all of this within VBA.

    Any suggestions?
    See my past post on pivot tables

  12. #12
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Creating a Pivot Table based off an ever changing range...

    Quote Originally Posted by Joven76 View Post
    Hey Mike,

    I'm not sure this will work for what I'm trying to do. Let me try to explain. We have a list of inventory items that are currently on back order. I've set up the spreadsheet using VBA so that it only shows orders needing inventory 45 days into the future, so as you can see, it will change from day to day.

    So there is one inventory line item with their quantity for each order. Therefore there can be and are multiple line items of the same inventory part number and quantity. The pivot table shows me these part numbers and the total quantity of all the line items.

    This information will then be drawn into another spreadsheet using a VBA macro, so I need to do all of this within VBA.

    Any suggestions?

    Explain why it wont work.
    You already said you have more or less rows correct? This captures those.

    Do yourself a favor and post a sample data set.

  13. #13
    Registered User
    Join Date
    09-12-2014
    Location
    Morrisville, NC
    MS-Off Ver
    2013
    Posts
    40

    Re: Creating a Pivot Table based off an ever changing range...

    Here is a sample set of data:

    Invt ID Description PromDate BO qty
    660422 Customization kit: 9/26/2014 1
    660423 Wristband dark grey 9/26/2014 1
    110-3614B ZONE INTERFACE UNIT PCB (ZIU) 9/10/2014 1
    110-3628C TELCO PCB - ONE FOR EACH ANALOG LINE 10/1/2014 2
    18A424 CORRIDOR/DOOR LIGHT 4 LAMP, 12V - BEIGE 9/25/2014 3
    200-1073 AIR PAD/ CALL CORD SINGLE - 10FT 9/15/2014 30
    200-1171 CALL CORD SINGLE PUSH BUTTON - 6FT 6/15/2014 6
    211-1297A COVER CORR + ZONE LT 9/18/2014 12
    438-537C CABLE KIT (8') CONNECTS TO 37-PIN PC6K 9/5/2014 38
    438-537C CABLE KIT (8') CONNECTS TO 37-PIN PC6K 9/19/2014 14
    439-0003-001 LICENSE - POCKET PAGE BRIDGE 6/15/2014 1
    4A2481B SINGLE PATIENT STATION - 3 GANG - GRAY 8/29/2014 4
    4A2481B SINGLE PATIENT STATION - 3 GANG - GRAY 9/5/2014 3
    4A2481B SINGLE PATIENT STATION - 3 GANG - GRAY 9/23/2014 6
    4A2481B SINGLE PATIENT STATION - 3 GANG - GRAY 9/25/2014 3
    4A3092A STAFF/DUTY STATION - INTERCOM AND TONE 9/25/2014 4
    9A2220 STAFF EMERGENCY STATION - GREEN PUSH BUT 9/25/2014 3
    9A3006 SHOWER STATION - PULL CORD 9/25/2014 1
    9B2100 MANUAL PRESENCE STATION - GRAY- 3 LEV 9/25/2014 3
    CISCO-BRIDGE V2 Cisco Telergy Bridge with 10 User Licenses 9/19/2014 1
    DISCOUNT AS10190-23% Customer Discount 7/31/2014 1
    DISCOUNT 12% Discount# AS10119, Customer Discount 6/15/2014 1
    ET9B2106 LAV/SHOWER STATION - PULL CORD - GRAY ET 9/25/2014 3
    GPO-1 Amerinet - GPO 7/10/2014 1
    GPO-3 Government - GPO 7/1/2014 1
    GPO-3 Government - GPO 7/1/2014 1
    GPO-3 Government - GPO 7/1/2014 1
    HC-ADT HL -7 ADT INTERFACE 7/1/2014 1
    HC-ADT HL -7 ADT INTERFACE 7/10/2014 1
    HC-ADT HL -7 ADT INTERFACE 6/15/2014 1
    HC-ANNUN ANNUNCIATOR 7/1/2014 1
    HC-ANNUN ANNUNCIATOR 7/1/2014 1
    HC-ANNUN ANNUNCIATOR 9/19/2014 1
    HC-ANNUN ANNUNCIATOR 9/19/2014 1
    HC-ANNUN ANNUNCIATOR 9/19/2014 4
    HC-ANNUN ANNUNCIATOR 9/24/2014 1
    HC-ANNUN ANNUNCIATOR 9/26/2014 8
    HC-ANNUN ANNUNCIATOR 6/15/2014 1


    When I run a pivot table, this is the result I get, which is what I'm looking for.

    Invt ID Total
    110-3614B 1
    110-3628C 2
    18A424 3
    200-1073 30
    200-1171 6
    211-1297A 12
    438-537C 52
    439-0003-001 1
    4A2481B 16
    4A3092A 4
    660422 1
    660423 1
    9A2220 3
    9A3006 1
    9B2100 3
    CISCO-BRIDGE V2 1
    DISCOUNT 2
    ET9B2106 3
    GPO-1 1
    GPO-3 3
    HC-ADT 3
    HC-ANNUN 18

    Because I'm looking at items that are needed prior to 45 days out, the list can grow and shrink on a daily basis. How could I incorporate your code into a pivot table using a macro?
    Last edited by Joven76; 09-16-2014 at 04:24 PM.

  14. #14
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Creating a Pivot Table based off an ever changing range...

    Post a workbook LOL not the data to the forum! haha.

  15. #15
    Registered User
    Join Date
    09-12-2014
    Location
    Morrisville, NC
    MS-Off Ver
    2013
    Posts
    40

    Re: Creating a Pivot Table based off an ever changing range...

    BackOrder Report By Order No 40740ascombo.xls

    Oh, yea, I knew that... Duh!

  16. #16
    Registered User
    Join Date
    09-12-2014
    Location
    Morrisville, NC
    MS-Off Ver
    2013
    Posts
    40

    Re: Creating a Pivot Table based off an ever changing range...

    Hey Mike,

    My apologies for thinking your method wouldn't work. After doing more research last night and this AM on what Dynamic Ranges were, I fully understand what you were talking about now. I tested it, rebuilt the macro, and it worked perfectly! Now onto the next step of this project.

    Just in case anyone else was wondering how it was done, I've posted the code below:

    Please Login or Register  to view this content.
    Thanks again Mike!

  17. #17
    Forum Contributor
    Join Date
    03-06-2013
    Location
    Salt Lake City, Utah
    MS-Off Ver
    2007, 2010
    Posts
    127

    Re: Creating a Pivot Table based off an ever changing range...

    Thought I might add my two cents.

    I tried mikeTron's method and it worked perfectly, but as an alternative have you thought about creating a table for your data set and then creating your pivot table from that. It should do exactly what you need and won't require VBA.
    BrownBoy

    If happy, mark "SOVLED" & add to "REP"

  18. #18
    Registered User
    Join Date
    09-12-2014
    Location
    Morrisville, NC
    MS-Off Ver
    2013
    Posts
    40

    Re: Creating a Pivot Table based off an ever changing range...

    For my particular project, I need VBA because this is just a small portion of a macro I'm building to compile 3 to 4 reports into one summary workbook.

  19. #19
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Creating a Pivot Table based off an ever changing range...

    Quote Originally Posted by BrownBoy View Post
    Thought I might add my two cents.

    I tried mikeTron's method and it worked perfectly, but as an alternative have you thought about creating a table for your data set and then creating your pivot table from that. It should do exactly what you need and won't require VBA.

    Tables are GREAT if you have a small file and small data and not many calculations in a workbook. If you have a complex file then I prefer to avoid the overhead of a table, but good suggestion! I forget about using tables so much since I typically play with too much data or complex models lately.

+ 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. Changing data range in Pivot table
    By michelemcgeoy in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 06-06-2014, 09:46 PM
  2. [SOLVED] Dynamically Changing Position of Pivot Based on Size of Another Pivot Table
    By ggilzow in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-26-2013, 02:42 PM
  3. [SOLVED] Pivot Table VBA Changing Data Range
    By jwh591 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 06-14-2012, 04:04 PM
  4. changing range selection for pivot table based on worksheet
    By twhitezell in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-07-2010, 11:49 AM
  5. Creating two different charts based on a single pivot table based on condition
    By exlnovice in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-26-2008, 06:21 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