+ Reply to Thread
Results 1 to 9 of 9

Extract data to create a pivot table/chart

  1. #1
    Forum Contributor
    Join Date
    02-14-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2013
    Posts
    328

    Extract data to create a pivot table/chart

    I have data as shown in my sample data file where I would like to eventually
    create a graph.

    The first step would be to extract the data from selected Stores.

    The next step would be to sum the data for each category (Beans, Apples)
    combining the data for all stores for each date.

    It is probably possible to combine these two steps into one.

    Once the data is looking like the data I have in Col M:P
    I would like to create a bar graph.

    The data will be updated daily and so I would like the table/pivot table
    to update automatically/dynamically if possible.

    The Store name on the graph could be simplified to 'StoreTotals'.

    I hope with the sample file, this will be clear.

    Any guidance would be greatly appreciated.

    P.S. There are more than 100,000 rows of data and more than 200 'Stores'.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    02-14-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2013
    Posts
    328

    Re: Extract data to create a pivot table/chart

    I'm not sure how I did it, but I managed to come up with a pivot table and graph
    that is doing the trick.

    It took a lot of experimenting.

    The only thing I need to check now is if the chart will update properly when new data is added.

    ...
    Well just checked now and it is not updating.

    Even worse, when I tried to manually refresh the pivot table it gave:

    'Reference is not valid' error.

    Probably something to do with the name of the table...
    ...

    Well I was right. I changed the name of the table and it is refreshing now.
    But there is still one problem that I can use some help with.

    My pivot table has rows that have collapsed data in them.

    All the rows were collapsed, but when I refreshed the table to get
    the new data, the new data was added to the bottom of the table
    and was not collapsed!

    This naturally messed up the chart that is linked to the PT.

    So my question now is, how can I refresh the table so that the new data rows added
    to the PT are collapsed like all the other ones above them?
    Last edited by ChrisXcel; 08-23-2021 at 09:27 PM.

  3. #3
    Forum Contributor
    Join Date
    02-14-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2013
    Posts
    328

    Re: Extract data to create a pivot table/chart

    Is this the right type of code to take care of the refreshing?

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,059

    Re: Extract data to create a pivot table/chart

    You only need 1 line: ActiveWorkbook.RefreshAll

  5. #5
    Forum Contributor
    Join Date
    02-14-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2013
    Posts
    328

    Re: Extract data to create a pivot table/chart

    Quote Originally Posted by josephteh View Post
    You only need 1 line: ActiveWorkbook.RefreshAll
    Thanks Joseph, I will try it out.

  6. #6
    Forum Contributor
    Join Date
    02-14-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2013
    Posts
    328

    Re: Extract data to create a pivot table/chart

    Well my first line above only worked one-time.

    I tried Joseph's line above but it didn't refresh my pivot table.

    Any other suggestions?

  7. #7
    Forum Contributor
    Join Date
    02-14-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2013
    Posts
    328

    Re: Extract data to create a pivot table/chart

    Just to help you with some additional information that might
    be of aid in troubleshooting my problem.

    The data in my data sheet that my pivot table is based on is cleared
    at the start of a new session.
    Then new data is added to the sheet.

    I have named the data range, which I understand is all that is needed to
    allow for an expanding data range.

    So does clearing the data sheet have an effect on the named data range?
    Will the named data range be also cleared?

    If so, what is the solution to maintaining a named data range, and
    at the same time clearing that same data each time a macro is run?
    Last edited by ChrisXcel; 08-24-2021 at 07:11 PM.

  8. #8
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,059

    Re: Extract data to create a pivot table/chart

    Sorry, I have limited VBA knowledge. Let the forum experts answer you.

  9. #9
    Forum Contributor
    Join Date
    02-14-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2013
    Posts
    328

    Re: Extract data to create a pivot table/chart

    Quote Originally Posted by ChrisXcel View Post
    So does clearing the data sheet have an effect on the named data range?
    Will the named data range be also cleared?

    If so, what is the solution to maintaining a named data range, and
    at the same time clearing that same data each time a macro is run?

    Well the above was the specific problem that was preventing my macro from working.

    Most people probably maintain a single database (sheet) and simply add data to the bottom of
    the sheet as it becomes available.

    In my case, each day the sheet needs to be cleared and replaced by new data.
    This is because data is added throughout the sheet, not just to the bottom.

    What I was doing was creating a new Table name with the new data.
    But I didn't know that when the data was cleared each day and I tried to create
    this new Table name, I would get an error (trying to have one table on top of another).

    So what I ended up doing yesterday was writing macro code to create a New Table,
    name it and then refresh the pivot table.

    I know this is just one of many ways to address my problem.

    I also thought of possibly copying my new data into my NewData sheet, replacing
    all my previous data, except for the headers.
    That way I could maintain my Table name (which is used with my Pivot Table).
    But it would have involved coding that was too tricky for me.

    Anyway, currently all is working well.

+ 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. Create Pivot Table, Extract Colum/Row/Value Separately
    By ChristovJN in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-25-2021, 01:57 AM
  2. Replies: 6
    Last Post: 01-24-2017, 06:56 PM
  3. [SOLVED] calculating specific data from a pivot table to create a pivot chart in Excel 2016
    By cinstanl in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-15-2016, 12:14 PM
  4. Replies: 1
    Last Post: 07-22-2015, 07:16 AM
  5. Replies: 0
    Last Post: 03-06-2014, 07:21 AM
  6. Macro to create pivot table/pivot chart
    By Karina in forum Excel General
    Replies: 2
    Last Post: 10-27-2011, 10:33 PM
  7. create chart from pivot table data
    By Brontosaurus in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-18-2011, 04:51 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