• Using Subtotal to sum filtered column of numbers but exclude negative values

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Using Subtotal to sum filtered column of numbers but exclude negative values

    Author
    Topic
    #504738

    I am trying to find out how to sum a column of filtered numbers but not include any negative values in the sum.
    The SUBTOTAL function works on the filtering part but I can’t find a way to limit it to non-negative numbers.
    Any suggestions?

    Thank you for your help.

    Viewing 5 reply threads
    Author
    Replies
    • #1554523

      ryandric,

      Welcome to the Lounge as a new poster! :cheers:

      Are you using SubTotal on more than one column? If not just extend your filtering to filter the SubTotaled column to numbers > 0.

      Setup:
      43767-STBase

      Select Groups A&C:
      43768-STGroupFilter

      Set Number Filter:
      43769-STGTZero

      Results:
      43770-STResults

      HTH :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1554548

      Thank you for your quick reply. I should have been clearer in my explanation.
      I am filtering on columns A and B but Subtotaling column C. Columns A and B are text and column C has numbers in it.
      The Subtotaled column does not have a filter.

    • #1554552

      ryandric,

      So is there a reason you can’t filter Column C for numbers > 0? :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1554672

      ryandric,

      The following formula will subtotal positive numbers in a filtered list. It assumes you have a header in cell A1 and the data is in the range A2:A99. You can place the formula in A100

      =SUMPRODUCT(–(A2:A99>0),SUBTOTAL(9,OFFSET(A2:A99,ROW(A2:A99)-ROW(A2),0,1)))

      HTH,
      Maud

    • #1554674

      Maud,

      Thank you. This is what I was looking for. I am not able to filter column C because the negative values still need to be visible.

      • #1554757

        Hi ryandric

        I like Maud’s formula method.

        ..another method is to use a custom function:

        Code:
        Function sumVisiblePositive(r As Range)
        
        For Each cell In r.Cells
        If cell.Height  0 Then
        zValue = cell.Value
        If IsNumeric(zValue) Then
        If zValue > 0 Then
        zTotal = zTotal + zValue
        End If
        End If
        End If
        Next
        
        sumVisiblePositive = zTotal
        
        End Function
        

        You add this code to a standard vba module, and use it in the spreadsheet like any Excel formula, for example
        =sumVisiblePositive(A2:A99)

        zeddy

    • #1554837

      Zeddy,

      This VBA module works perfectly.
      Thank you.

      ryandric

    Viewing 5 reply threads
    Reply To: Using Subtotal to sum filtered column of numbers but exclude negative values

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: