+ Reply to Thread
Results 1 to 4 of 4

VBA PivotTable Automatic Range-selection

  1. #1
    Registered User
    Join Date
    06-19-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    6

    VBA PivotTable Automatic Range-selection

    Hi

    I've recorded a Macro for generating a PivotTable.
    By recording the macro Excel took "WERE!R1C1:R20466C14", however I need it to select the actual datarange which can be bigger but also smaller.
    How do I adjust it the code so it will select the actual Data Row/Column size?

    Please Login or Register  to view this content.
    Thanks!

  2. #2
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: VBA PivotTable Automatic Range-selection

    Hi..

    You need to add some code that will detect the bottom of your range..

    Lets say your data is from Column A:J.. starting in row 2.. but the number of rows can change..

    In this case.. you need to find the last used row in your data range..

    First Dimension your variable..

    Please Login or Register  to view this content.
    then.. to find the Last Row (assuming you have data in Column A all the way till the bottom)..

    Please Login or Register  to view this content.
    Then... Your Pivot Table code can be..

    Please Login or Register  to view this content.
    Be careful using..
    Please Login or Register  to view this content.
    As that will limit the Excel versions your Pivot table will work in.. but if its only for your local machine.. thats fine..


    Just noticed you might need to find the last used column...

    This is the most reliable thing for that..

    Please Login or Register  to view this content.
    Last edited by apo; 06-20-2013 at 04:23 AM.

  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA PivotTable Automatic Range-selection

    perhaps
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  4. #4
    Registered User
    Join Date
    06-19-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: VBA PivotTable Automatic Range-selection

    Thank you, works excellent!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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