+ Reply to Thread
Results 1 to 6 of 6

Pivot table macro, Dynamic range

  1. #1
    Registered User
    Join Date
    08-31-2012
    Location
    Denver
    MS-Off Ver
    Excel 2007
    Posts
    3

    Pivot table macro, Dynamic range

    I'm pretty new to VBA and I'm working on a macro that will create a pivot table based on a sheet that will have additional data (rows) every few days. Therefore I need the range the pivot is pulling from to be dynamic. Selecting the entire sheet that the data is coming from is also an option, but I couldn't successfully find a way to do that.

    I've been fiddling with Dim's without much success( I don't think I understand their syntax very well) to try to make the rows variable.

    Any suggestions are appreciated. Thanks for your help.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Pivot table macro, Dynamic range

    Hi, V3rse,

    Excel will record the area in R1C1-Notation but you could try to substitute the code by
    Please Login or Register  to view this content.
    instead of
    Please Login or Register  to view this content.
    Please be informed that if there are blanks in the names used it should read "'Data Fresh'" instead of "Data Fresh".

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    08-31-2012
    Location
    Denver
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Pivot table macro, Dynamic range

    That notation does seem more user friendly, but how can I use that to make the range dynamic? I tried your code and it only wants to select cell A1. I tried changing the range values to "a1:z50000" and it did the same thing.

    50000 would be more than enough to cover the cells I need after the data it's pulling from is complete, but some of the cells will likely be blank during that time. Will that keep the pivot table from working correctly?

    note: there was also an extra period which I removed

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Pivot table macro, Dynamic range

    Hi, V3rse,

    how can I use that to make the range dynamic?
    Already done with CurrentRegion as that marks the continuous area around Range("A1") no matter how many rows there will be in the sheet. Continuous means no empty rows or columns which will end the block of data.

    Maybe use one of these alternatives as well: name the range "Database" and rely on that as range-object, make your data a table, get the last row of data and use that in the code:
    Please Login or Register  to view this content.
    Sorry about the extra period.

    Ciao,
    Holger

  5. #5
    Registered User
    Join Date
    08-30-2010
    Location
    kolkata
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Pivot table macro, Dynamic range

    Please Login or Register  to view this content.
    Last edited by arlu1201; 11-22-2012 at 03:42 AM.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Pivot table macro, Dynamic range

    jashiag,

    Welcome to the forum.

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature below this post.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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