Excel – Remove duplicate and SUM Quantity at the same time

135 viewsexcelexcel vbarowexcel excel vba row
0

I am trying to modify “remove duplicate and sum qty” the from my excel using VBA.
below here is modification code..

Sub mcr_Collect_Unique()
Dim ws As Worksheet, wsu As Worksheet
Set ws = ActiveSheet
Set wsu = Sheets.Add(after:=Sheets(Sheets.Count))
ws.Cells(1, 1).CurrentRegion.Copy Destination:=wsu.Cells(1, 1)
With wsu.Cells(1, 1).CurrentRegion
    With .Cells.Resize(.Rows.Count, .Columns.Count)
        .RemoveDuplicates Columns:=Array(1, 1, 2), Header:=xlYes
        Debug.Print Application.Count(wsu.Columns(3))
        With .Cells(2, 3).Resize(Application.Count(wsu.Columns(3)), 1)
            .FormulaR1C1 = "=SUMIFS('" & ws.Name & "'!C,'" & ws.Name & _
              "'!C[-2],RC[-2],'" & ws.Name & "'!C[-2],RC[-2],'" & ws.Name & _
              "'!C[-1],RC[-1])"
            '.Cells = .Value
        End With
    End With
End With
End Sub

The program work perfectly however the result is come out in different sheet.
How should I modify the code such a way that it come out in same sheet?

Thanks.