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:
<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
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:
Datum | shift leader | Operator | Activiteit | Truck | Numbers | Lines | Cartons | Start | Einde |
02-May-16 | Jack | Picking crates | 14132229 | 1 | 4 | 10 | 09:30 | 10:30 | |
02-May-16 | Jack | Picking crates | 14132229 | 455 | 222 | 99 | |||
02-May-16 | Jack | Picking crates | 14132229 | 211 | 397 | 472 | |||
02-May-16 | Jack | Picking crates | 14132229 | 553 | 4 | 418 | |||
02-May-16 | Jack | Picking crates | 14132229 | 1 | 22 | 10 | |||
02-May-16 | Jack | Picking crates | 14132229 | 566 | 211 | 222 | |||
02-May-16 | Jack | Picking crates | 14132229 | 21 | 113 | 88 | |||
02-May-16 | Jack | Picking crates | 14132229 | 33 | 52 | 73 | |||
02-May-16 | Peter | Picking crates | 14132232 | 4 | 1 | 11 | 11:20 | 12:20 | |
02-May-16 | Peter | Picking crates | 14132232 | 56 | 8 | 87 | |||
02-May-16 | Peter | Picking crates | 14132232 | 3 | 7 | 22 | |||
02-May-16 | Peter | Picking crates | 14132232 | 44 | 9 | 71 | |||
02-May-16 | Peter | Picking crates | 14132232 | 38 | 50 | 95 | |||
02-May-16 | Peter | Picking crates | 14132232 | 21 | 1 | 34 | |||
02-May-16 | Peter | Picking crates | 14132232 | 4 | 22 | 20 | |||
02-May-16 | Peter | Picking crates | 14132232 | 43 | 1 | 11 | |||
02-May-16 | Peter | Picking crates | 14132232 | 48 | 40 | 56 | |||
02-May-16 | Peter | Picking crates | 14132232 | 94 | 8 | 78 | |||
02-May-16 | John | Picking crates | 14132233 | 18 | 20 | 22 | 12:10 | 12:20 | |
02-May-16 | John | Picking crates | 14132233 | 11 | 19 | 200 | |||
02-May-16 | John | Picking crates | 14132233 | 211 | 212 | 311 | |||
02-May-16 | John | Picking crates | 14132233 | 655 | 433 | 655 | |||
02-May-16 | John | Picking crates | 14132233 | 15 | 48 | 99 | |||
02-May-16 | John | Picking crates | 14132233 | 87 | 77 | 28 | |||
02-May-16 | Jack | Picking crates | 14132118 | 411 | 312 | 298 | |||
02-May-16 | Jack | Picking crates | 14132118 | 233 | 156 | 288 | |||
02-May-16 | Jack | Picking crates | 14132118 | 456 | 211 | 99 |
<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