I have a similar issue as the poster in this thread: VBA to merge duplicate rows and sum values in certain column
I took the code and made the adjustments to look at column A and column I for total quantity. The issue I have is that the quantity is not really adding together, rather combining the two numbers. So if there are 3 parts with quantity 1, I am ending up with 111 as the quantity and not 3.
How do I get them to actually add together?
Sub merge_duplicate()
Dim Rng As Range, Dn As Range, nRng As Range
Dim n As Long, lr As Long, Txt As String
Application.ScreenUpdating = False
lr = Range("A" & Rows.Count).End(3).Row
Set Rng = Range("A2:A" & lr)
Set nRng = Range("A" & lr + 1)
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
For Each Dn In Rng
Txt = Dn.Value
If Not .Exists(Txt) Then
.Add Txt, Dn.Offset(, 8)
Else
.Item(Txt).Value = .Item(Txt).Value + Dn.Offset(, 8).Value
Set nRng = Union(nRng, Dn)
End If
Next
nRng.EntireRow.Delete
End With
Application.ScreenUpdating = True
I took the code and made the adjustments to look at column A and column I for total quantity. The issue I have is that the quantity is not really adding together, rather combining the two numbers. So if there are 3 parts with quantity 1, I am ending up with 111 as the quantity and not 3.
How do I get them to actually add together?
Sub merge_duplicate()
Dim Rng As Range, Dn As Range, nRng As Range
Dim n As Long, lr As Long, Txt As String
Application.ScreenUpdating = False
lr = Range("A" & Rows.Count).End(3).Row
Set Rng = Range("A2:A" & lr)
Set nRng = Range("A" & lr + 1)
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
For Each Dn In Rng
Txt = Dn.Value
If Not .Exists(Txt) Then
.Add Txt, Dn.Offset(, 8)
Else
.Item(Txt).Value = .Item(Txt).Value + Dn.Offset(, 8).Value
Set nRng = Union(nRng, Dn)
End If
Next
nRng.EntireRow.Delete
End With
Application.ScreenUpdating = True