+ Reply to Thread
Results 1 to 5 of 5

SUMPRODUCT Formula with Dynamic Last Row

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    228

    SUMPRODUCT Formula with Dynamic Last Row

    Hello Everyone,

    I've looked online and found a couple threads that were similar but nothing that was exactly what I was looking for. I am trying to put together a SUMPRODUCT formula with a dynamic last row. I think my issue isn't with the conditions, but with the column that it's supposed to be summing. Here is the code.

    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    dLastRow = Sheets("Data").Cells(Rows.Count, "A").End(xlUp).Row
        Range("R2").Formula = "=SUMPRODUCT(--('Data'!C$2:C$" & dLastRow & "=C2),--('Data'!I$2:I$" & dLastRow & "=H2),('Data'!Z$2:Z$ & dLastRow))"
        Range("R2").AutoFill Destination:=Range("R2:R" & LastRow), Type:=xlFillDefault

    If someone could show me what I have wrong here, I'd appreciate it.

    Thanks!

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: SUMPRODUCT Formula with Dynamic Last Row

    this look problamatic

    Range("R2").Formula = "=SUMPRODUCT(--('Data'!C$2:C$" & dLastRow & "=C2),--('Data'!I$2:I$" & dLastRow & "=H2),('Data'!Z$2:Z$ & dLastRow))"
    maybe
    Range("R2").Formula = "=SUMPRODUCT(--('Data'!C$2:C$" & dLastRow & "=C2),--('Data'!I$2:I$" & dLastRow & "=H2),('Data'!Z$2:Z$ & dLastRow & "))"
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    228

    Re: SUMPRODUCT Formula with Dynamic Last Row

    Yeah, I believe that was one of the little changes I tried out. I end up getting a "Compile error: Expected: end of statement" error that highlights the second to last parenthesis.

  4. #4
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    228

    Re: SUMPRODUCT Formula with Dynamic Last Row

    Ahhh - I think I got it... I just added one more quotation after 'Data'!Z$2:Z$. So the final code looks like:

    Range("R2").Formula = "=SUMPRODUCT(--('Data'!C$2:C$" & dLastRow & "=C2),--('Data'!I$2:I$" & dLastRow & "=H2),('Data'!Z$2:Z$" & dLastRow & "))"

  5. #5
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: SUMPRODUCT Formula with Dynamic Last Row

    actually even mine is missing a Quote....

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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