+ Reply to Thread
Results 1 to 7 of 7

Change range in formula based on changing row count

Hybrid View

  1. #1
    Registered User
    Join Date
    05-13-2010
    Location
    New Brunwsick, Canada
    MS-Off Ver
    Excel 2013
    Posts
    22

    Change range in formula based on changing row count

    Okay.... I'm stumped and am likely making this more complicated than it needs to be... so here I am.

    I have a bunch of formulas that are working great. The issue is that the number of rows changes frequently as data is added or removed from the source sheet ("Sheet X"). I'm trying to avoid selecting an enormous number of rows "to be safe" and have run into issues with the row range I used shrinking when data is deleted.

    I would like to "calculate" the range so that it automatically changes when the number of rows changes. Is there a way that I can recalculate the range (within the formulas) without using VBA?

    Example formula here:
    =SUMPRODUCT((YEAR('Sheet X'!R2:R200)=YEAR(TODAY())-1)*('Sheet X'!B2:B200="Implemented"))

    I'd like to be able to have "200" change to match the number of rows in use (using a formula).

    Thanks in advance.
    Razz

  2. #2
    Valued Forum Contributor ron2k_1's Avatar
    Join Date
    09-30-2009
    Location
    Not the USA
    MS-Off Ver
    Excel 2003, 2007
    Posts
    606

    Re: Change range in formula based on changing row count

    The formula is evaluating data tables that are available on the same workbook. If you Insert rows, the range will update automatically. I guess you can you some sort of INDIRECT to accommodate the array formula =MAX(ROW(A1:A500)*(A1:A500<>"")) which will give the last used row, but it will be very slow and memory hungry.

    I suggest that you just do a find/replace business (Ctrl + H) and look for the row number you have on your formula and then replace it with whatever you have. I, personally, would include at least 10% more rows than you actually need just to be safe.
    Ron
    Knowledge is knowing that a tomato and pepper are fruits. Wisdom is knowing whether to put these in a fruit salad

    Kindly

    [1] Use code tags. Place "[code]" before the first line of code and "[/code"]" after the last line of code. Exclude quotation marks
    [2] Mark your post [SOLVED] if it has been answered satisfactorily by editing your original post in advanced mode.
    [3] Thank (using the little scale) those that provided useful help; its nice and its very well appreciated

  3. #3
    Registered User
    Join Date
    05-13-2010
    Location
    New Brunwsick, Canada
    MS-Off Ver
    Excel 2013
    Posts
    22

    Re: Change range in formula based on changing row count

    Tried this approach for a while and it was becoming a real pain to maintain which is why I was looking for a better solution. (Multiple people were updating the source data and not always inserting to maintain the range).

  4. #4
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Change range in formula based on changing row count

    You can use Dynamic Named Ranges.

    See link: http://www.contextures.com/xlnames01.html

  5. #5
    Valued Forum Contributor ron2k_1's Avatar
    Join Date
    09-30-2009
    Location
    Not the USA
    MS-Off Ver
    Excel 2003, 2007
    Posts
    606

    Re: Change range in formula based on changing row count

    Yep, dynamic named ranges will do it, here is one I was looking at right:
    http://www.excelforum.com/excel-gene...n-formula.html

  6. #6
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Change range in formula based on changing row count

    In Excel 2007+, convert the data source to an Excel Table (Ribbon Menu > Insert > Table)

    Make sure your table has headers.
    Excel automatically treats tables as dynamic ranges and you can use the table headers in the formulas to reference the entire table/column - no need to create dynamic named ranges.

    So you might end up with a formula similar to:

    =SUMPRODUCT((YEAR(Table1[Date])=YEAR(TODAY())-1)*(Table1[Status]="Implemented"))

    Where Date and Status are the header names in the table.
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  7. #7
    Registered User
    Join Date
    05-13-2010
    Location
    New Brunwsick, Canada
    MS-Off Ver
    Excel 2013
    Posts
    22

    Smile Re: Change range in formula based on changing row count

    Thanks so much everyone. The dynamic range idea is working beautifully. I didn't even know I could do that. I love it when I learn something new. You saved me a lot of work & may I say... you rock!

    Thanks Again.
    Razz

+ 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