Sum If, for duplicates?

mattbnorris

New Member
Joined
Sep 17, 2019
Messages
25
Office Version
  1. 2016
Platform
  1. Windows
Morning,

I have a list of monetary values that are associated to reference numbers. What formula can I use in order to sum up the monetary values of the reference numbers if they are the same reference numbers.

For example

Ref: #123 Value: £100
#123 £200
#124 £50
#123 £70
#125 £50
#124 £90

Therefore I want a formula that will add these values based on finding the duplicate reference number in the list.

Ref: #123 Value: £370
#124 £140
#125 £50

Thanks in advance,
Matt
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hey,

Lets say your references are in cells A1:A6, with values in B1:B6

=SUMIF($A$1:$A$6,"#123",$B$1:$B$6)

Might be easier if instead of "#123" as the second parameter, you put all the unique references in to another column, then reference the column and drag formula down. Like so:

ABCDE
1#123100#123370
2#123200#124140
3#12450#12550
4#12370
5#12550
6#12490

<tbody>
</tbody>


Where E1 is:
=SUMIF($A$1:$A$6,D1,$B$1:$B$6)

Which can be dragged down.
 
Last edited:
Upvote 0
Hi,
Just in case , If you want try this code


Code:
Sub test()
    Dim a As Variant
    Application.ScreenUpdating = False
    a = Range("a1:a" & Cells(Rows.Count, 1).End(xlUp).Row).Resize(, 2)
    With CreateObject("scripting.dictionary")
        For i = 1 To UBound(a)
'           a(i, 1) = Mid(a(i, 1), 2, 10)   ' It's up to you "#"
            a(i, 2) = Mid(a(i, 2), 2, 10)
            If Not .exists(a(i, 1)) Then
                .Add a(i, 1), a(i, 2)
            Else
                .Item(a(i, 1)) = .Item(a(i, 1)) + a(i, 2) * 1
            End If
            kk = .keys
            itm = .items
        Next
        k = .Count
        Range("d1:d" & .Count) = Application.Transpose(.keys)
        Range("e1:e" & .Count) = Application.Transpose(.items)
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Welcome to the MrExcel board!

Another option, especially if the original data is not changing, is to use Excel's built-in Pivot Table feature (on the Insert ribbon tab)

Excel Workbook
ABCDE
1Ref:Value:Row LabelsSum of Value:
2#123100#123370
3#123200#124140
4#12450#12550
5#12370Grand Total560
6#12550
7#12490
8
PT
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,849
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top