osinrider04
New Member
- Joined
- Jan 7, 2015
- Messages
- 9
I have a data set where the combination of 3 columns needs to be consolidated, and then their values summed. Here is a pretend scenario: I have Employee Name, Contract Number, Task Number. Right now the data is built by a daily entry of these inputs. This means an employee will have many entries per day if they are working on numerous contracts and tasks. What I would like to do is remove duplicates of these 3 columns (which I have done in my VBA already), but I also want to sum the values of these combinations before deleting the duplicates.
My code at the moment is only good enough to delete the entries and keep only non-dupes. The obvious problem is that once I have removed dupes I can no longer get my summation of the values that were there before. It might be worth noting that my data will always be changing. The names of employees, contract numbers, and task numbers will be expanding and changing.
Essentially I will take a repository of data and create a whole new tab with this consolidated list of entries.
Sub Dedupe()
Application.ScreenUpdating = False
Dim lastrow As Long
With ThisWorkbook.Worksheets("SubInvBackUpCopied (2)")
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
lastrow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
lastrow = 1
End If
'Array(4, 5, 7, 8) means 4 for D, 5 for E, and 8 for H
.Range("A1:P" & lastrow).RemoveDuplicates Columns:=Array(4, 5, 8), _
Header:=xlYes
End With
Application.ScreenUpdating = True
My code at the moment is only good enough to delete the entries and keep only non-dupes. The obvious problem is that once I have removed dupes I can no longer get my summation of the values that were there before. It might be worth noting that my data will always be changing. The names of employees, contract numbers, and task numbers will be expanding and changing.
Essentially I will take a repository of data and create a whole new tab with this consolidated list of entries.
Sub Dedupe()
Application.ScreenUpdating = False
Dim lastrow As Long
With ThisWorkbook.Worksheets("SubInvBackUpCopied (2)")
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
lastrow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
lastrow = 1
End If
'Array(4, 5, 7, 8) means 4 for D, 5 for E, and 8 for H
.Range("A1:P" & lastrow).RemoveDuplicates Columns:=Array(4, 5, 8), _
Header:=xlYes
End With
Application.ScreenUpdating = True