using VBA to summarize duplicated values in a table

Somapadidar

New Member
Joined
Oct 2, 2021
Messages
12
Office Version
  1. 2019
Platform
  1. Windows
I have a file including 3 different columns. The contents of first one "name", are chosen from a list which has been defined in data validation before. It means its contents is limited. The content of second column "order" is numbers, which may be from 1 to 30 but there is no limitations on it. I want to find repeated rows versus columns "name" & "order" and if it occurs, and write the number(order) which has been repeated and the sum of their 3rd columns, "amount", next to it in a table below, in front of its related name. The point is that for a particular name more than one different repeated order may occur which should be put in a row in the table respectively and of course there may be no duplicated value which means no data would be added in table. I want to have just duplicated value and the number of their repetition if it is possible. I mean those with number of repetition is >1. this is a sample and the desired table which has been filed by mine. I want to use VBA in this project.
NAMEORDERAMOUNT
AA484
BB35
CC665
DD612
EE745
FF976
AA489
DD19
BB333
EE312
AA234
EE756
AA276
BB312
BB145
and here is desired result which can be written for example from column "j":

orderamountcountorderamountcount
AA4173221102
BB350
CC
DD
EE71013
FF
GG
HH
II
JJ
KK
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
As you forgot to elaborate where is the source data (just a range or a real Excel table ?!) and where should be the expected result …​
 
Upvote 0
Yes but still don't know where ! Read again post #2 but well this time …​
Or are you enough confident with your Excel / VBA skills to amend any VBA demonstration a helper could share ?​
 
Upvote 0
I want to have the result table in the same sheet (a bit apart from the main data)
and here is my desired result I want to have it in the sheet which wanted to be produced by VBA:
orderamountcountorderamountcount
AA4173221102
BB350
CC
DD
EE71013
FF
GG
HH
II
JJ
KK
 
Upvote 0
If you are enough confident with your Excel / VBA skills I could post some 'one shot code'​
meaning I won't modify it for what you forgot to elaborate but are you ?​
 
Upvote 0
An Excel basics VBA one shot demonstration for starters :​
VBA Code:
Sub Demo1()
         Dim F$, S$, V, R&, L&, W, C%
         Application.ScreenUpdating = False
         [J1].CurrentRegion.Clear
    With [A1].CurrentRegion.Columns
        .Item("A:B").AdvancedFilter 2, , [J1], True
         F = .Item(1).Address(, , xlR1C1) & ",RC10," & .Item(2).Address(, , xlR1C1) & ",RC[-"
         S = "=SUMIFS(" & .Item(6).Address(, , xlR1C1) & "," & F & "1])"
         F = "=COUNTIFS(" & F & "2])"
    End With
    With [J1].CurrentRegion.Rows
         If .Count = 1 Then Beep: Exit Sub
        .Sort .Cells(1), 1, Header:=1
         V = .Value2
        .Item("2:" & .Count).Clear
    End With
        R = 1
    For L = 2 To UBound(V)
        If V(L, 1) = W Then C = C + 3 Else C = 11: R = R + 1: W = V(L, 1): Cells(R, 10).Value2 = W
        Cells(R, C).Resize(, 3).Formula = Array(V(L, 2), S, F)
    Next
    With [J1].CurrentRegion.Columns
        .Range("B1:D1").Value2 = [{"Order #1","Amount #1","Count #1"}]
         If .Count > 4 Then .Range("B1:D1").AutoFill .Cells(2).Resize(, .Count - 1)
    End With
         Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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