+ Reply to Thread
Results 1 to 9 of 9

[SOLVED] SUMPRODUCT with DYNAMIC range

  1. #1
    Registered User
    Join Date
    01-30-2020
    Location
    UK
    MS-Off Ver
    2013
    Posts
    82

    [SOLVED] SUMPRODUCT with DYNAMIC range

    Hi All

    I have the following formula which is copied down from cell A4 but now the INDEX range number of rows will change every week. Can this formula be modified to find the last row?

    Please Login or Register  to view this content.
    Thanks
    Last edited by warp765; 02-13-2020 at 01:03 PM.

  2. #2
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: SUMPRODUCT with DYNAMIC range

    You can use
    EUT!$B$2:INDEX(EUT!$B:$B,Counta(EUT!$B:B)) as example.

  3. #3
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454

    Re: SUMPRODUCT with DYNAMIC range

    Hi,

    I would use named ranges in this instance.

    Column B's named range might look like this..

    =$B$2:INDEX($B$2:$B$50000,MATCH(9.999E307,$B$2:$B$50000,1))

    Column C and F like so..

    =$C$2:INDEX($C$2:$C$50000,MATCH(9.999E307,$B$2:$B$50000,1))
    =$F$2:INDEX($F$2:$F$50000,MATCH(9.999E307,$B$2:$B$50000,1))

    note the use of column B in all formulas to make sure the number of rows in each dynamic range is the same to suit the SUMPRODUCT formula.

    You could also use the CountA version shown by BMV above, but if there are blanks within the range, it will fail.
    Last edited by sweep; 02-12-2020 at 07:25 AM.
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  4. #4
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: SUMPRODUCT with DYNAMIC range

    Quote Originally Posted by sweep View Post
    You could also use the CountA version shown by BMV above, but if there are blanks within the range, it will fail.
    but if there are string in the B column it will fail also

    Without example it's difficult to help.

    However, I have another question Why do you use sumproduct? MAX and CSE calculate it.

  5. #5
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454

    Re: SUMPRODUCT with DYNAMIC range

    but if there are string in the B column it will fail also
    True enough!!

    I would use sumproduct here as it's known to be a little faster than an array function. Given the size of the ranges, warp785 might notice the calculation speed. I guess it's only around 10%, but every little helps?!

  6. #6
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: SUMPRODUCT with DYNAMIC range

    The last nonblank row in col B would be given by =MATCH(1,INDEX(0/NOT(ISBLANK(B:B)),0)).

  7. #7
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: SUMPRODUCT with DYNAMIC range

    Quote Originally Posted by sweep View Post
    I would use sumproduct here as it's known to be a little faster than an array function.
    in the case of Sum and product is main operation but here MAX will return only one and sumproduct will replace CSE and
    =INDEX(MAX((D10:D15=D11)*C10:C15);) or =LOOKUP(9E+36;MAX((D10:D15=D11)*C10:C15)) also work without CSE.
    and =AGGREGATE(14;6;C10:C15/(D10:D15=D11);1) available for 2013

    Quote Originally Posted by hrlngrv View Post
    The last nonblank row in col B would be given by =MATCH(1,INDEX(0/NOT(ISBLANK(B:B)),0)).
    - it's worse then use 100 000 in first formula because this operation will calculate 1 048 576 cells. and
    Please Login or Register  to view this content.
    - much shorter quicker and with the same problem.
    Last edited by BMV; 02-12-2020 at 09:17 AM.

  8. #8
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: SUMPRODUCT with DYNAMIC range

    Quote Originally Posted by hrlngrv View Post
    The last nonblank row in col B would be given by =MATCH(1,INDEX(0/NOT(ISBLANK(B:B)),0)).
    Quote Originally Posted by BMV View Post
    . . .
    - it's worse then use 100 000 in first formula because this operation will calculate 1 048 576 cells. and
    Please Login or Register  to view this content.
    - much shorter quicker and with the same problem.
    In a new workbook, enter

    A1: 0
    B1: x
    A2: =CHOOSE(A1,MATCH(1,INDEX(0/NOT(ISBLANK(B:B)),0)),LOOKUP(1,0/(B:B<>""),ROW(B:B)),MATCH(1,INDEX(0/NOT(ISBLANK(prune(B:B))),0)),lastrow(B:B))

    Insert a general VBA module, and enter this code.

    Please Login or Register  to view this content.
    Now run prof. On my system (a VM with not a lot of RAM) I get the following results in the Immediate window.

    1 08:06:32 08:07:00 0.1399999982 2253
    2 08:07:01 08:07:24 0.1150000017 2193
    3 08:07:25 08:07:25 0.0000000000 2380
    4 08:07:26 08:07:26 0.0000000000 2386
    - -------- -------- ------------ ----
    3 08:07:50 08:08:00 0.0049999999 23279
    4 08:08:01 08:08:07 0.0030000001 22815

    3 and 4 each took less than a second for 200 iterations, so I increased MAXITER to 2000 and reran them. This does show that your lookup formula is about 18% faster than my match formula, but using a little VBA chops orders of magnitude off the calculation time. Note: <>"" isn't the same thing as blank. If the last cell with visible contents was B99 and there were IFERROR(...,"") formulas in B100:B200 all returning "", your lookup formula would return 99 while my match formula would return 200.
    Last edited by hrlngrv; 02-12-2020 at 12:32 PM.

  9. #9
    Registered User
    Join Date
    01-30-2020
    Location
    UK
    MS-Off Ver
    2013
    Posts
    82

    Re: SUMPRODUCT with DYNAMIC range

    Thanks to all of you for your helpful suggestions 😀

+ 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] Sumproduct over dynamic range
    By sipa in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-29-2019, 08:20 AM
  2. Dynamic range from which to use =SUMPRODUCT()
    By Dralky in forum Excel General
    Replies: 10
    Last Post: 06-30-2018, 12:59 AM
  3. Replies: 2
    Last Post: 01-20-2017, 04:27 PM
  4. Sumproduct of Dynamic Range
    By deepak2jadav in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 06-28-2014, 09:01 AM
  5. Sumproduct for dynamic range
    By Bob@Sun in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-05-2010, 06:32 AM
  6. Sumproduct, dynamic range
    By jmicdk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2008, 08:43 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