+ Reply to Thread
Results 1 to 5 of 5

VBA to find and select Last row in a dynamic Pivot Table

  1. #1
    Registered User
    Join Date
    06-09-2011
    Location
    Frisco, Texas
    MS-Off Ver
    Excel 2007
    Posts
    5

    VBA to find and select Last row in a dynamic Pivot Table

    I am having issues with a VBA script. The Spreadsheet is linked to a SQL DB and updated with data from scripts that are executing throughout the day. This is then fed to a dashboard. We have a Baseline that shows in the Date column as 0/0 and 1/1. I need a way to ensure that the 1/1 is always in the last row of the chart so the baseline shows across the entire range of dates. The current method is to declare a variable and add 1 to it whenever we iterate through the sort for the other dates. However everyday the 1/1 baseline column ends up further to the beginning until it is next to the 0/0 in position 2.


    So I am trying to find a way to have the macros find the last row of the Date field and then set the position to be equal to the last row.

    Thank you,

    Paul

  2. #2
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: VBA to find and select Last row in a dynamic Pivot Table

    Hi Paul,

    Can you post a sample workbook so that the Pivot Table can be seen and macros? There are a number of ways to do this!


    David

    Please remember, your request is clearer if you attach a sample workbook.
    - Click on Go Advanced and click on the Paper Clip.
    When you reply please make it clear WHO you are responding to by mentioning their name.
    If this has been of assistance, please advise. A little thanks goes a long way.
    - Please click on the *Add Reputation button at the bottom of helpful responses.
    Please mark your thread as SOLVED:
    - Click Thread Tools above your first post, select "Mark your thread as Solved".

  3. #3
    Registered User
    Join Date
    06-09-2011
    Location
    Frisco, Texas
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: VBA to find and select Last row in a dynamic Pivot Table

    Hi David,

    Thank you for your reply. I had to format a sample workbook with dummy data so my response has been delayed. The macros is slightly different as far as the date sort goes. Since we are using A SQL DB now and I have the query set to pull in the needed data and sort by date. The issue is with the 1/1, which should display in the last row of the Date field to make the pivot chart Baseline extend across the chart.

    I should clarify that the data set is always growing throughout the day. Therefore the last row is always changing.


    Thank you,

    Paul
    Attached Files Attached Files
    Last edited by PaulHudgins; 02-03-2014 at 02:14 PM.

  4. #4
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: VBA to find and select Last row in a dynamic Pivot Table

    Hi Paul,

    The answer may be too simple! I changed the 0/0 and 1/1 to dates (1/1/2014 and 28/2/2014).

    The chart now shows the way I imagine you want to see it! The problem is that the Baseline markers are in text while the rest are dates. The text is being sorted by the Pivot Chart to the front.

    I also added a small macro called PivotOldItemsDelete. Your Pivot List was full of rubbish left over from the past. If you run this macro every time, it will ensure that the data in the dropdown is the data on the Data Sheet. Not a whole lot of other dates.

    So, just anchor your baselines with dates of your choosing before and after the date renag you are dealing with.


    Regards,

    David


    When you reply please make it clear WHO you are responding to by mentioning their name.

    If this has been of assistance, please advise. A little thanks goes a long way.
    - Please click on the *Add Reputation button at the bottom of helpful responses.

    Please mark your thread as SOLVED:
    - Click Thread Tools above your first post, select "Mark your thread as Solved".
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    06-09-2011
    Location
    Frisco, Texas
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: VBA to find and select Last row in a dynamic Pivot Table

    Hi David,

    Thank you for your reply. I didn't think about changing the dates, I was too busy trying to make a way for the old formatting to work. Thank you for the other macros as well. I modified the SQL query that we are using on our other spreadsheet to only pull in the necessary data. I 'll experiment with your changes/recommendations.

    Regards,

    Paul

+ 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. Pivot Table select all Pivot Items not working as intended
    By rasonline in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-13-2014, 05:22 PM
  2. Pivot table error message but can't find the offending pivot table
    By dcoates in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 01-22-2013, 08:45 AM
  3. Pivot Table-Select Pivot Items
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-28-2011, 01:20 PM
  4. Pivot Table based on dynamic table
    By CydMM in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-28-2010, 06:59 AM
  5. Dynamic Pivot Chart based on Pivot Table.
    By excelkeechak in forum Excel General
    Replies: 3
    Last Post: 12-01-2009, 09:23 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