• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Sum of individual values in a cell

bizlife

New Member
Hi all,

I have a sheet where there is data in column A. I want to sum few cells and display the result in a cell showing individual values as well. For eg - cell A3 is 200, A5 is 120, A10 is 180. I want the sum in cell B1(say) to be shown as =200+120+180. I will be filtering the values in column A based on criterias in different columns, hence the cells are different everytime the criteria changes. I used subtotal but it only shows the total value and not the individual values being summed up. Please help me do this.

Thanks in advance.
Pankaj
 
Pankaj

Try this UDF

Code:
Function Show_Filtered_Sum(myRng As Range) As String

Dim SubTot As String
Dim c As Range

Application.Volatile
Application.EnableEvents = False

SubTot = "="
For Each c In myRng
    If c.EntireRow.Hidden = False Then
        SubTot = SubTot + CStr(c) + "+"
    End If
Next

Show_Filtered_Sum = Left(SubTot, Len(SubTot) - 1)

Application.EnableEvents = True

End Function

to use it either:

=Show_Filtered_Sum(Table1[Field Name])
or
=Show_Filtered_Sum(C1:C100)
 
Pankaj

Try this UDF

Code:
Function Show_Filtered_Sum(myRng As Range) As String

Dim SubTot As String
Dim c As Range

Application.Volatile
Application.EnableEvents = False

SubTot = "="
For Each c In myRng
    If c.EntireRow.Hidden = False Then
        SubTot = SubTot + CStr(c) + "+"
    End If
Next

Show_Filtered_Sum = Left(SubTot, Len(SubTot) - 1)

Application.EnableEvents = True

End Function

to use it either:

=Show_Filtered_Sum(Table1[Field Name])
or
=Show_Filtered_Sum(C1:C100)

Hi Hui,
That worked like magic. Thanks for the help.
I have just started learning VBA and the power of coding amazes me everyday. Please help me with tips to learn the language faster and in depth.

Thanks once again. :)
 
Back
Top