+ Reply to Thread
Results 1 to 9 of 9

[SOLVED] SUMPRODUCT with DYNAMIC range

Hybrid View

warp765 [SOLVED] SUMPRODUCT with... 02-12-2020, 07:04 AM
BMV Re: SUMPRODUCT with DYNAMIC... 02-12-2020, 07:19 AM
sweep Re: SUMPRODUCT with DYNAMIC... 02-12-2020, 07:22 AM
BMV Re: SUMPRODUCT with DYNAMIC... 02-12-2020, 07:35 AM
hrlngrv Re: SUMPRODUCT with DYNAMIC... 02-12-2020, 09:03 AM
sweep Re: SUMPRODUCT with DYNAMIC... 02-12-2020, 08:44 AM
BMV Re: SUMPRODUCT with DYNAMIC... 02-12-2020, 09:06 AM
hrlngrv Re: SUMPRODUCT with DYNAMIC... 02-12-2020, 12:28 PM
warp765 Re: SUMPRODUCT with DYNAMIC... 02-12-2020, 12:37 PM
  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?

    =SUMPRODUCT(MAX((EUT!$B$2:$B$10000=$C4)*(EUT!$C$2:$C$10000=$U$3)*(EUT!$F$2:$F$10000)))
    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
    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)).

  6. #6
    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?!

  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
    =LOOKUP(2;1/(B:B<>"");ROW(B:B))
    - 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
    =LOOKUP(2;1/(B:B<>"");ROW(B:B))
    - 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.

    Option Explicit
    
    
    Function prune(rng As Range) As Range
      Set prune = Intersect(rng, rng.Parent.UsedRange)
    End Function
    
    
    Function lastrow(rng As Range) As Long
      If rng.Columns.Count = 1 Then
        Set rng = Intersect(rng, rng.Parent.UsedRange)
        Set rng = rng.Rows(rng.Rows.Count)
        If IsEmpty(rng.Value2) Then Set rng = rng.End(xlUp)
        lastrow = rng.Row
      End If
    End Function
    
    
    Sub prof()
      Const MAXITER As Long = 200
      Const MAXBUMP As Long = 20
    
      Dim dt As Date, j As Long, k As Long
    
      For j = 1 To 4
        '# following 2 statements ensure a clean slate for each expression
        [B2:B1048576].ClearContents
        ThisWorkbook.Save
        dt = Now
        [A1].Value2 = j
        For k = 1 To MAXITER
          [B1].Offset([A2].Value2 + Application.WorksheetFunction.RandBetween(1, MAXBUMP), 0).Value2 = "x"
        Next k
        Debug.Print j, Format(dt, "hh:mm:ss"), Format(Now, "hh:mm:ss"), Format((Now - dt) * 86400# / MAXITER, "0.0000000000"), [A2].Value2
      Next j
    
      [A1].Value2 = 0
      [B2:B1048576].ClearContents
      ThisWorkbook.Save
    
    End Sub
    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