Find repeated CELLS in VBA and create another cell

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, 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. this is a sample and the desired table which has been filed by mine. I want to use VBA in this project.
NAMEORDERAMOUNT
1AA484
2BB35
3CC665
4DD612
5EE745
6FF976
7AA489
8DD19
9BB333
10EE312
11AA234
12EE756
13AA276
14BB312
15BB145
orderamountorderamount
AA41732110
BB350
CC
DD
EE7101
FF
GG
HH
II
JJ
KK
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Welcome to MrExcel Message Board.
Try:
VBA Code:
Sub Test()
Dim Lr As Long, Lr2 As Long
Lr = Range("A" & Rows.Count).End(xlUp).Row
  Range("A1:B" & Lr).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("J1:K1"), Unique:=True
Lr2 = Range("J" & Rows.Count).End(xlUp).Row
Range("J1:K" & Lr2).Sort Key1:=Range("J1"), Order1:=xlAscending, Key2:=Range("K1"), Order2:=xlAscending, Header:=xlYes
Range("L1").Value = "Amount"
Range("L2:L" & Lr2).Formula = "=SUMIFS($F$2:$F$" & Lr & ",$A$2:$A$" & Lr & ",J2,$B$2:$B$" & Lr & ",K2)"

End Sub
 
Last edited:
Upvote 0
Sub Test() Dim Lr As Long, Lr2 As Long Lr = Range("A" & Rows.Count).End(xlUp).Row Range("A1:B" & Lr).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("J1:K1"), Unique:=True Lr2 = Range("J" & Rows.Count).End(xlUp).Row Range("J1:K" & Lr2).Sort Key1:=Range("J1"), Order1:=xlAscending, Key2:=Range("K1"), Order2:=xlAscending, Header:=xlYes Range("L1").Value = "Amount" Range("L2:L" & Lr2).Formula = "=SUMIFS($F$2:$F$" & Lr & ",$A$2:$A$" & Lr & ",J2,$B$2:$B$" & Lr & ",K2)" End Sub
Thanks a lot
it worked
the only point is that how i can do this just for order>1?
 
Upvote 0
Try this:
VBA Code:
Sub Test()
Dim Lr As Long, Lr2 As Long
Lr = Range("A" & Rows.Count).End(xlUp).Row
  Range("A1:B" & Lr).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("J1:K1"), Unique:=True
Lr2 = Range("J" & Rows.Count).End(xlUp).Row
Range("J1:K" & Lr2).Sort key1:=Range("J1"), order1:=xlAscending, Key2:=Range("K1"), Order2:=xlAscending, Header:=xlYes
Range("L1:M1").Value = Array("Amount", "Count")
Range("L2:L" & Lr2).Formula = "=SUMIFS($F$2:$F$" & Lr & ",$A$2:$A$" & Lr & ",J2,$B$2:$B$" & Lr & ",K2)"
Range("M2:M" & Lr2).Formula = "=CountIFS($A$2:$A$" & Lr & ",J2,$B$2:$B$" & Lr & ",K2)"
Range("J1:M" & Lr2).AutoFilter Field:=4, Criteria1:="=1", Operator:=xlAnd
Range("J2:M" & Lr2).SpecialCells(xlCellTypeVisible).ClearContents
Range("J1:M" & Lr2).AutoFilter
Range("J1:M" & Lr2).Sort key1:=Range("J1:J" & Lr2), order1:=xlAscending, Header:=xlYes
End Sub
 
Upvote 0
NAMEORDERAmountCount
NAMEORDERAMOUNTAA21102
AA484AA4173
2​
BB35BB350
3​
CC665EE7101
2​
DD612
EE745
FF976
AA489
DD19
BB333
EE312
AA234
EE756
AA276
BB312
BB145
amountorderamount
 
Upvote 0
I appreciate you a lot. Here is the result. It makes a table for me at the top of the sheet(thanks)
, but the point is that it runs correctly just once and I cannot find why it did happen?
 
Upvote 0
Same result using Pivot Table

Book3
ABCDEFGH
1NAMEORDERAMOUNTValues
2AA484NAMEORDERAmount Count
3BB35AA21102
4CC66541732
5DD612BB3503
6EE745EE71012
7FF976
8AA489
9DD19
10BB333
11EE312
12AA234
13EE756
14AA276
15BB312
16BB145
Sheet1
 
Upvote 0
It just filters column j to m, it means it just shows 4 sliding flash in the first row of mentioned columns(J, K, L ,M)!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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