+ Reply to Thread
Results 1 to 10 of 10

SumProduct with dynamic last row for data in separate worksheet

  1. #1
    Registered User
    Join Date
    12-30-2014
    Location
    US
    MS-Off Ver
    2010
    Posts
    17

    SumProduct with dynamic last row for data in separate worksheet

    I'm using the following SumProduct formula and need the formula to update based on the last rows of data in a 2nd worksheet. The cells in bold are where the reference for the last row with data in the 2nd tab (Transactions Export) should be updating. For instance, if I copy paste a data dump that has 10 rows of data, I need the formula to adjust to D2:D11 and E2:E11. Is there some sort of VBA code I can use to lookup the last row in each of those columns and update the formula accordingly? Any help much appreciated.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: SumProduct with dynamic last row for data in separate worksheet

    Hello,

    I suggest you use dynamic range names. Use the Name Manager in the Formulas ribbon and create these two names (I assume row 1 holds labels for the columns)

    TransactionsD ='Transactions Export'!$D$2:INDEX('Transactions Export'!$D:$D,COUNTA('Transactions Export'!$D:$D))
    TransactionsE =OFFSET(TransactionsD,0,1)

    Then you can use

    Please Login or Register  to view this content.
    You could build the Index formula straight into the Sumproduct, too, but it's easier to read and maintain with named ranges.

    cheers, teylyn
    Last edited by teylyn; 05-18-2015 at 10:06 PM.

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: SumProduct with dynamic last row for data in separate worksheet

    You could use dynamic ranges.

    Name: Range1 (or whatever you want to call it)
    Refers to:

    ='Transactions Export'!$D$2:INDEX('Transactions Export'!$D$2:$D$50000,MATCH(1E100,'Transactions Export'!$D$2:$D$50000))

    Name: Range2 (or whatever you want to call it)
    Refers to:

    ='Transactions Export'!$E$2:INDEX('Transactions Export'!$E$2:$E$50000,MATCH(1E100,'Transactions Export'!$E$2:$E$50000))

    Adjust for reasonable end of ranges where I use down to row 50000.

    Then your formula becomes:

    =SUMPRODUCT(--(MONTH(Range1)=MONTH($A$1)),Range2)
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: SumProduct with dynamic last row for data in separate worksheet

    With Sumproduct I would only use as many rows as have data. Otherwise the formula can become pretty slow.

  5. #5
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: SumProduct with dynamic last row for data in separate worksheet

    Quote Originally Posted by teylyn View Post
    With Sumproduct I would only use as many rows as have data.
    We don't know how many rows of data there are.

    That's why we're using dynamic ranges!

  6. #6
    Registered User
    Join Date
    12-30-2014
    Location
    US
    MS-Off Ver
    2010
    Posts
    17

    Re: SumProduct with dynamic last row for data in separate worksheet

    Is there a way I can offset to end the ranges on the 2nd to last row? It turns out using the last row doesn't work because only some of the columns have data in them (it's just a totals row which I don't need). D has one less row of data than column E so SumProduct returns #VALUE! unless they match.

  7. #7
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: SumProduct with dynamic last row for data in separate worksheet

    Make both named ranges refer to the same column for the last row. (probably D since it has the fewer rows)

    Using Tony's example

    Name: Range1 (or whatever you want to call it)
    Refers to:

    ='Transactions Export'!$D$2:INDEX('Transactions Export'!$D$2:$D$50000,MATCH(1E100,'Transactions Export'!$D$2:$D$50000))

    Name: Range2 (or whatever you want to call it)
    Refers to:

    ='Transactions Export'!$E$2:INDEX('Transactions Export'!$E$2:$E$50000,MATCH(1E100,'Transactions Export'!$D$2:$D$50000))

  8. #8
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: SumProduct with dynamic last row for data in separate worksheet

    =SUMPRODUCT((MONTH('Transactions Export'!D2:INDEX('Transactions Export'!D:D,MATCH(10^10,'Transactions Export'!D:D)))=(MONTH($A$1)))*('Transactions Export'!E2:INDEX('Transactions Export'!E:E,MATCH(10^10,'Transactions Export'!D:D))))
    Please Login or Register  to view this content.
    TRY THE ABOVE FORMULA
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  9. #9
    Registered User
    Join Date
    12-30-2014
    Location
    US
    MS-Off Ver
    2010
    Posts
    17

    Re: SumProduct with dynamic last row for data in separate worksheet

    Thanks all - that adjustment works perfectly!

  10. #10
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: SumProduct with dynamic last row for data in separate worksheet

    You're welcome. We appreciate the feedback!

    If your question has been solved please mark the thread as being solved.

    In the menu bar above the very first post select Thread Tools, then select Mark this thread as solved.

+ 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(SUMIF(INDIRECT with Dynamic Worksheet Range
    By decipher in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-07-2014, 05:40 AM
  2. Dynamic Range Graph with data in separate file?
    By gapollo in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 07-29-2013, 09:44 AM
  3. [SOLVED] Getting data from a separate sheet by date (dynamic)
    By georgegovensky in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-16-2012, 07:35 AM
  4. How do create a Dynamic List on a Separate Worksheet
    By graphictees in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-18-2011, 01:56 PM
  5. Replies: 0
    Last Post: 08-03-2010, 04:11 PM

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