+ Reply to Thread
Results 1 to 5 of 5

VBA for sumifs() with varying last row

  1. #1
    Registered User
    Join Date
    05-26-2011
    Location
    Overland Park, KS
    MS-Off Ver
    Excel 2007
    Posts
    13

    VBA for sumifs() with varying last row

    I thought this would be possible but I get a "Compile Error" when entering the following code:

    LastRow = Cells(Rows.Count, "DH").End(xlUp).Row
    ActiveCell.Select
    ActiveCell.Formula = _
    "=SUMIFS($DG$4:$DG$" & LastRow & ",$A$4:$A$" & LastRow & ",""Unidentified*"", _
    $DF$4:$DF$" & LastRow & ",""September 2011"")

    I am attempting a sumifs() formula that has a varying last row.

    Any help would be appreciated.

    Thanks.
    Last edited by snelson0713; 09-15-2011 at 04:10 PM.

  2. #2
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: VBA for sumifs() with varying last row

    On which line does the code err? You might try:
    Please Login or Register  to view this content.
    Use that as a replacement for:
    Please Login or Register  to view this content.
    You will have to modify whichever column your primary data is in if it isn't the A column.

    Regards,
    Tom
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  3. #3
    Registered User
    Join Date
    05-26-2011
    Location
    Overland Park, KS
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: VBA for sumifs() with varying last row

    The error was coming up on the last row of code. I just removed the break (" _") at the end of the second row so the formula is all on one line and it worked how I expected it to but I don't understand why.

    Thanks for the feedback.

  4. #4
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: VBA for sumifs() with varying last row

    Using a space followed by a _ is a designated line break in code. If it's not done properly, the following line won't be considered part of the previous line. You probably needed to start the second line with an & and quotes.

  5. #5
    Registered User
    Join Date
    05-26-2011
    Location
    Overland Park, KS
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: VBA for sumifs() with varying last row

    Perfect, thanks!

+ 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