+ Reply to Thread
Results 1 to 5 of 5

VBA Sumif with Dynamic Range

Hybrid View

  1. #1
    Registered User
    Join Date
    04-18-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    34

    Question VBA Sumif with Dynamic Range

    Hello,

    I was hoping someone could help me with a sumif using a dynamic range. Basically I want to sum Column R of my spreadsheet for everything but a "renewal" license type which is in column N of my spreadsheet. Each loop of the code will change the number of rows so it has to be dynamic. I would like to place this at the end of the below code. Can someone possibly assist me?
    HTML Code: 

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,741

    Re: VBA Sumif with Dynamic Range

    Each loop of the code will change the number of rows so it has to be dynamic
    What does that mean? You haven't shown a loop.

    So, column R is a different formula to all the others? Or does it go in every cell in column R from row 2 down to the final row (which you have already calculated)

    And is this a different worksheet to the rest of the code?

    ActiveWorkbook.Worksheets("Closed Deals").Range("A" & LR + 1).EntireRow.Font.Bold = True
    ActiveWorkbook.Worksheets("Closed Deals").Range("A2:AE" & LR + 1).Borders(xlEdgeBottom).LineStyle = xlDouble

    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    04-18-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: VBA Sumif with Dynamic Range

    Sorry I probably shouldn't have said loop. I meant when I run the macro there will be a different number of rows every time. In column N of my spreadsheet I have listed different license types. In column R I have the total amount of the license. I want to create a sumif using this formula (Cells(FinalRow + 3, 18).Formula = ??) in order to sum the all license totals except those with a license type of "renewal" so that it dynamically adds the sum to the bottom of the rows in column # 18.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,741

    Re: VBA Sumif with Dynamic Range

    Ok, got that, thought that might be it. Back shortly.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,741

    Re: VBA Sumif with Dynamic Range

    Try this:

    Option Explicit
    
    Sub sDynamicRange_TMS()
    
    Dim FinalRow As Long
    
    With ActiveWorkbook.Worksheets("Closed Deals")
        FinalRow = .Range("A" & .Rows.Count).End(xlUp).Row
        .Range(.Cells(FinalRow + 1, 15), .Cells(FinalRow + 1, 24)).Formula = "=sum(O2:O" & FinalRow & ")"
        .Cells(FinalRow + 1, 30).Formula = "=sum(AD2:AD" & FinalRow & ")"
    
        .Range("A" & FinalRow + 1).EntireRow.Font.Bold = True
        .Range("A2:AE" & FinalRow + 1).Borders(xlEdgeBottom).LineStyle = xlDouble
    
        .Cells(FinalRow + 3, 17).Value = "Total Quota Credit Less Renewals"
        .Cells(FinalRow + 3, 17).WrapText = True
        .Cells(FinalRow + 3, 17).Font.Bold = True
        .Cells(FinalRow + 3, 18).Formula = "=SUMIF($N2:$N" & FinalRow & ",""<>Renewal"",$R2:$R" & FinalRow & ")"
    End With
    
    End Sub

+ 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] SUMIF formula with dynamic column range and then expand the width of SUM range
    By gravythief in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-26-2017, 08:36 AM
  2. [SOLVED] SUMIF with dynamic sum range
    By msp_excel in forum Excel General
    Replies: 10
    Last Post: 12-23-2014, 01:47 PM
  3. Sumif with dynamic range
    By XL2008 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-06-2014, 01:17 PM
  4. Sumif and dynamic range
    By Bpd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2013, 01:36 AM
  5. Sumif and dynamic range
    By Bpd in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-08-2013, 01:36 AM
  6. VBA SUMIF in Dynamic Range
    By Cowzilla in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-17-2012, 05:28 PM
  7. Sumif for dynamic range
    By Praneetbvb in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-02-2012, 07:14 AM

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