I found this code but i can't get it to work for my cell range. My example is below. "Corrected Order" is in col C, "Qty" is in col D. I want to remove the duplicates in col C, summing the corresponding values in col D and paste into range F1:G40. The code below works if I copy&paste col C to Col A, otherwise it removes duplicates but values are all "0"??
A B C D
Corrected Order (LCP) Qty
Orange 12
Pear 9
Pear 9
Pear 6
Orange 6
Orange 3
Orange 1
Apple 34
Apple 4
Apple 4
Apple 67
Option Explicit
Sub main()
With Worksheets("Fruit Stock") '<== change "Fruit Stock" as per your actual sheet name
With .Range("C1:D40").Resize(.Cells(.Rows.Count, 3).End(xlUp).Row)
.Copy
With .Offset(, .Columns.Count + 1)
.PasteSpecial xlPasteValues ' copy value and formats
.Columns(2).Offset(1).Resize(.Rows.Count - 1, 1).FormulaR1C1 = "=SUMIF(C1,RC1,C[-" & .Columns.Count + 1 & "])"
.Value = .Value
.RemoveDuplicates 1, xlYes
End With
End With
End With
End Sub