+ Reply to Thread
Results 1 to 4 of 4

Making a macro that works on data with a varying amount of rows

  1. #1
    Registered User
    Join Date
    12-28-2018
    Location
    Pennsylvania, US
    MS-Off Ver
    Excel 2016-Windows 10
    Posts
    35

    Making a macro that works on data with a varying amount of rows

    I'll preface this by saying I don't know much about vba except for how to record a macro.

    Every month I download an excel list of invoices with their customers and amounts and make some reports from that data. I want to record a macro to change the process of making the report to just a few minutes rather than manually redoing the report every month.

    The problem I'm having is that the amount of rows in the list of invoices changes(one month it may have 5000 rows while another it has 6000) and I use pivot tables in the report. So when I go to run the macro on a report that has a more rows than what was originally recorded, the pivot table doesn't get the right amount of data because the reference to make the table is always something like $A$1:$G$5000. It doesn't automatically size itself to the length of the data like a normal pivot table would.

    Is there any work around to this so that it always gets the right amount of data from report to report? The columns never change it's just the amount of rows that varies.

    Thanks in advance for any help.

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Making a macro that works on data with a varying amount of rows

    Hi chough10,

    The typical way to do this is by creating a variable to capture the LastRow

    Please Login or Register  to view this content.
    Here's a reference that you could use also >> https://www.thespreadsheetguru.com/b...lumn-using-vba
    HTH
    Regards, Jeff

  3. #3
    Registered User
    Join Date
    12-28-2018
    Location
    Pennsylvania, US
    MS-Off Ver
    Excel 2016-Windows 10
    Posts
    35

    Re: Making a macro that works on data with a varying amount of rows

    Ah, dynamic is the word I was looking for. This looks like it'll work. Thanks for the help

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Making a macro that works on data with a varying amount of rows

    You are very welcome and thanks for the rep/feedback.

+ 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. [SOLVED] Calculate Projected Annual amount from Dollar value (Amount) and varying time intervals
    By old dawg in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-16-2016, 07:29 PM
  2. Making Multiple Tables Have The Same Amount of Rows Using Excel VBA
    By Stryker152 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-28-2015, 07:12 PM
  3. macro to import varying data rows into fixed table
    By aselly22 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2014, 12:51 AM
  4. Copying cell value into a varying amount of rows
    By flord in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-18-2013, 02:15 PM
  5. Replies: 13
    Last Post: 02-12-2013, 12:49 PM
  6. Macro - Charts - Varying Source Data Rows
    By hdogg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-31-2007, 06:37 PM
  7. Replies: 5
    Last Post: 08-01-2006, 12:23 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