Modified code sum repeat data
Solved/Closed
abdelfatah_0230
Posts
73
Registration date
Thursday July 18, 2019
Status
Member
Last seen
July 23, 2022
-
Updated on Oct 8, 2020 at 11:42 AM
abdelfatah_0230 Posts 73 Registration date Thursday July 18, 2019 Status Member Last seen July 23, 2022 - Oct 27, 2020 at 06:11 PM
abdelfatah_0230 Posts 73 Registration date Thursday July 18, 2019 Status Member Last seen July 23, 2022 - Oct 27, 2020 at 06:11 PM
Related:
- Modified code sum repeat data
- Battery reset code - Guide
- Samsung volume increase code - Guide
- How to get whatsapp verification code online - Guide
- Cs 1.6 code - Guide
- Samsung keypad reset code - Guide
3 responses
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Oct 12, 2020 at 12:01 PM
Oct 12, 2020 at 12:01 PM
Hi Abdel,
Why would a formula produce an incorrect result? Have you tried this one:
=SUMIF(A:A,D2,B:B)
Best regards,
Trowa
Why would a formula produce an incorrect result? Have you tried this one:
=SUMIF(A:A,D2,B:B)
Best regards,
Trowa
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Oct 26, 2020 at 12:37 PM
Oct 26, 2020 at 12:37 PM
Hi Abdel,
Your code looks overly complicated, so I decided to write my own. Here is my take on getting the requested task done:
Best regards,
Trowa
Your code looks overly complicated, so I decided to write my own. Here is my take on getting the requested task done:
Sub RunMe() Dim mFind As Range Columns("A:A").Copy Columns("D:D") Columns("D:D").RemoveDuplicates Columns:=1, Header:=xlYes For Each cell In Range("D2:D" & Range("D1").End(xlDown).Row) Set mFind = Columns("A:A").Find(what:=cell.Value, lookat:=xlWhole) fAddress = mFind.Address Do cell.Offset(0, 1).Value = cell.Offset(0, 1).Value + mFind.Offset(0, 1).Value Set mFind = Columns("A:A").FindNext(mFind) Loop While mFind.Address <> fAddress Next cell End Sub
Best regards,
Trowa
abdelfatah_0230
Posts
73
Registration date
Thursday July 18, 2019
Status
Member
Last seen
July 23, 2022
Oct 26, 2020 at 04:22 PM
Oct 26, 2020 at 04:22 PM
thanks Trowa but your code doesn't work well it sums values repeatedly each item it continues summing every time run the macro it supposing summing one if i time even run macro repeatedly
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Oct 27, 2020 at 12:33 PM
Oct 27, 2020 at 12:33 PM
Hi Abdel,
When you want to run the code multiple times, then you can clear the results first:
Or use the slightly adjusted code below:
The choice is yours.
Best regards,
Trowa
When you want to run the code multiple times, then you can clear the results first:
Range("D2:E" & Range("E1").End(xlDown).Row).ClearContents
Or use the slightly adjusted code below:
Sub RunMe() Dim mCount As Long Dim mFind As Range Columns("A:A").Copy Columns("D:D") Columns("D:D").RemoveDuplicates Columns:=1, Header:=xlYes For Each cell In Range("D2:D" & Range("D1").End(xlDown).Row) Set mFind = Columns("A:A").Find(what:=cell.Value, lookat:=xlWhole) fAddress = mFind.Address Do mCount = mCount + mFind.Offset(0, 1).Value Set mFind = Columns("A:A").FindNext(mFind) Loop While mFind.Address <> fAddress cell.Offset(0, 1).Value = mCount mCount = 0 Next cell End Sub
The choice is yours.
Best regards,
Trowa
abdelfatah_0230
Posts
73
Registration date
Thursday July 18, 2019
Status
Member
Last seen
July 23, 2022
Oct 27, 2020 at 06:11 PM
Oct 27, 2020 at 06:11 PM
many thanks ! Trowa it's perfect
Oct 17, 2020 at 06:21 AM
thanks again