VBA - filtering duplicates adding up multiple columns

Gestel

New Member
Joined
May 3, 2016
Messages
2
Hello Everyone!

During the last few weeks I have started to gain experience in VBA (with a lot of help from this forum and great joy so far),
yesterday, however I encountered a challenge I could not yet solve.

For my internship I need to analyse two databases which are constantly updated (therefore I would prefer VBA over a function),
but I'm struggling with duplicates which need to be added up and deleted afterwards.

The first original database looks as follows:

Datumshift leaderOperatorActiviteitTruckNumbersLinesCartonsStartEinde
02-May-16JackPicking crates14132229141009:3010:30
02-May-16JackPicking crates1413222945522299
02-May-16JackPicking crates14132229211397472
02-May-16JackPicking crates141322295534418
02-May-16JackPicking crates1413222912210
02-May-16JackPicking crates14132229566211222
02-May-16JackPicking crates141322292111388
02-May-16JackPicking crates14132229335273
02-May-16PeterPicking crates14132232411111:2012:20
02-May-16PeterPicking crates1413223256887
02-May-16PeterPicking crates141322323722
02-May-16PeterPicking crates1413223244971
02-May-16PeterPicking crates14132232385095
02-May-16PeterPicking crates1413223221134
02-May-16PeterPicking crates1413223242220
02-May-16PeterPicking crates1413223243111
02-May-16PeterPicking crates14132232484056
02-May-16PeterPicking crates1413223294878
02-May-16JohnPicking crates1413223318202212:1012:20
02-May-16JohnPicking crates141322331119200
02-May-16JohnPicking crates14132233211212311
02-May-16JohnPicking crates14132233655433655
02-May-16JohnPicking crates14132233154899
02-May-16JohnPicking crates14132233877728
02-May-16JackPicking crates14132118411312298
02-May-16JackPicking crates14132118233156288
02-May-16JackPicking crates1413211845621199


<tbody>
</tbody>

For me it is key to add up the Numbers, Lines and Cartons if the truck number is the same in this database
(as you can see a single time is added for either one truck or for one day for a single operator (like Jack in this example))
and delete the rows which were added up.

Additional information:
The file is a binary file.
has 9 sheets (the database is in the 8th sheet and named "Required for Macro").

I will post about the second database once we found a solution for this one.
I'm sorry for any grammer mistakes, I'm not a native speaker.

If I forgot anything please let me know!

Thank you!



PS:
This thread might be useful, it included the code shown below, unfortunately I'm not yet skilled enough to convert the code to my needs...

http://www.mrexcel.com/forum/excel-...licate-values-then-delete-duplicate-rows.html

Code:
Sub Test()    Dim Sh As Worksheet
    Dim LastRow As Long
    Dim Rng As Range
    Set Sh = Worksheets(1)
    Sh.Columns(5).Insert
    LastRow = Sh.Range("A65536").End(xlUp).Row
    With Sh.Range("A1:A" & LastRow).Offset(0, 4)
        .FormulaR1C1 = "=IF(COUNTIF(R1C[-4]:RC[-4],RC[-4])>1,"""",SUMIF(R1C[-4]:R[" & LastRow & "]C[-4],RC[-4],R1C[-1]:R[" & LastRow & "]C[-1]))"
        .Value = .Value
    End With
    Sh.Columns(4).Delete
    Sh.Rows(1).Insert
    Set Rng = Sh.Range("D1:D" & LastRow + 1)
    With Rng
        .AutoFilter Field:=1, Criteria1:="="
        .SpecialCells(xlCellTypeVisible).EntireRow.Delete
    End With
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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