Summarize data with multiple criteria

chunu

Board Regular
Joined
Jul 5, 2012
Messages
109
Office Version
  1. 2013
Platform
  1. Windows
  2. Mobile
Hi,
I need help to summarize data as shown in picture.
sum up duplicate invoices amount.
Thanks

filter.jpg
[/URL][/IMG]
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi,

Have you tried to Insert a Pivot Table ...?
 
Upvote 0
Hi
May be
Code:
Sub test()
    Dim a As Variant, lr, i, x, s, k, itm
    a = Range("b3:b" & Cells(Rows.Count, 1).End(xlUp).Row).Resize(, 4)
    With CreateObject("scripting.dictionary")
        For i = 1 To UBound(a)
            If a(i, 1) <> 0 Then
                If Not .exists(a(i, 1) & Chr(164) & a(i, 2) & Chr(164) & a(i, 3)) Then
                    .Add a(i, 1) & Chr(164) & a(i, 2) & Chr(164) & a(i, 3), a(i, 4)
                Else
                    .Item(a(i, 1) & Chr(164) & a(i, 2) & Chr(164) & a(i, 3)) = .Item(a(i, 1) & Chr(164) & a(i, 2) & Chr(164) & a(i, 3)) + a(i, 4)
                End If
            End If
        Next
        k = .keys
        itm = .items
        s = 1
        For i = 1 To .Count
            x = Split(k(i - 1), Chr(164))
            Range("g" & 3 + i - 1).Resize(, UBound(x) + 1) = x
            Range("g" & 3 + i - 1).Offset(, 3) = itm(i - 1)
        Next
    End With
 
Last edited:
Upvote 0
Hi
May be
Code:
Sub test()
    Dim a As Variant, lr, i, x, s, k, itm
    a = Range("b3:b" & Cells(Rows.Count, 1).End(xlUp).Row).Resize(, 4)
    With CreateObject("scripting.dictionary")
        For i = 1 To UBound(a)
            If a(i, 1) <> 0 Then
                If Not .exists(a(i, 1) & Chr(164) & a(i, 2) & Chr(164) & a(i, 3)) Then
                    .Add a(i, 1) & Chr(164) & a(i, 2) & Chr(164) & a(i, 3), a(i, 4)
                Else
                    .Item(a(i, 1) & Chr(164) & a(i, 2) & Chr(164) & a(i, 3)) = .Item(a(i, 1) & Chr(164) & a(i, 2) & Chr(164) & a(i, 3)) + a(i, 4)
                End If
            End If
        Next
        k = .keys
        itm = .items
        s = 1
        For i = 1 To .Count
            x = Split(k(i - 1), Chr(164))
            Range("g" & 3 + i - 1).Resize(, UBound(x) + 1) = x
            Range("g" & 3 + i - 1).Offset(, 3) = itm(i - 1)
        Next
    End With

Thanks mohadin
code is perfect but can you make option to filter by criteria , lets say criteria range cell m2, like advanced filter so i can get result for each customer separately.
 
Upvote 0
Hi,

Have you tried to Insert a Pivot Table ...?
thanks james006, i have tried pivot table and its works well but i need simple formula or vba. user mohadin has given vba code that looks good.
 
Upvote 0
Thanks mohadin
code is perfect but can you make option to filter by criteria , lets say criteria range cell m2, like advanced filter so i can get result for each customer separately.
NOt clear to me
Sorry
 
Upvote 0
NOt clear to me
Sorry
Currently its giving the result of whole data ( for all customers)
I am looking for criteria based , like if write customer name in cell m2 and hit command button it should give result only for that customer.
 
Upvote 0
Like this?
Code:
Sub test()    Dim a As Variant, lr, i, x, s, k, itm
    a = Range("b3:b" & Cells(Rows.Count, 1).End(xlUp).Row).Resize(, 4)
    With CreateObject("scripting.dictionary")
        For i = 1 To UBound(a)
            If a(i, 2) = Range("m2") And a(i, 2) <> "" Then
                If Not .exists(a(i, 1) & Chr(164) & a(i, 2) & Chr(164) & a(i, 3)) Then
                    .Add a(i, 1) & Chr(164) & a(i, 2) & Chr(164) & a(i, 3), a(i, 4)
                Else
                    .Item(a(i, 1) & Chr(164) & a(i, 2) & Chr(164) & a(i, 3)) = .Item(a(i, 1) & Chr(164) & a(i, 2) & Chr(164) & a(i, 3)) + a(i, 4)
                End If
            End If
        Next
        k = .keys
        itm = .items
        [G:I].ClearContents
        For i = 1 To .Count
            x = Split(k(i - 1), Chr(164))
            Range("g" & 3 + i - 1).Resize(, UBound(x) + 1) = x
            Range("g" & 3 + i - 1).Offset(, 3) = itm(i - 1)
        Next
    End With
End Sub
 
Last edited:
Upvote 0
Solution
Like this?
Code:
Sub test()    Dim a As Variant, lr, i, x, s, k, itm
    a = Range("b3:b" & Cells(Rows.Count, 1).End(xlUp).Row).Resize(, 4)
    With CreateObject("scripting.dictionary")
        For i = 1 To UBound(a)
            If a(i, 2) = Range("m2") And a(i, 2) <> "" Then
                If Not .exists(a(i, 1) & Chr(164) & a(i, 2) & Chr(164) & a(i, 3)) Then
                    .Add a(i, 1) & Chr(164) & a(i, 2) & Chr(164) & a(i, 3), a(i, 4)
                Else
                    .Item(a(i, 1) & Chr(164) & a(i, 2) & Chr(164) & a(i, 3)) = .Item(a(i, 1) & Chr(164) & a(i, 2) & Chr(164) & a(i, 3)) + a(i, 4)
                End If
            End If
        Next
        k = .keys
        itm = .items
        [G:I].ClearContents
        For i = 1 To .Count
            x = Split(k(i - 1), Chr(164))
            Range("g" & 3 + i - 1).Resize(, UBound(x) + 1) = x
            Range("g" & 3 + i - 1).Offset(, 3) = itm(i - 1)
        Next
    End With
End Sub
Excellent , Thank you so much.
 
Upvote 0
You are very well come
Thank you for the feedback
Be happy
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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