how to combine duplicate rows and sum the values 3 column in excel

前端 未结 2 497
青春惊慌失措
青春惊慌失措 2020-12-01 23:25

Hello everyone, I have a problem to create VBA excel to duplicate data.

How to combine duplicate rows and sum the values 3 column in excel?

Thank y

2条回答
  •  盖世英雄少女心
    2020-12-01 23:58

    this one uses Remove Duplicates:

    Sub dupremove()
    Dim ws As Worksheet
    Dim lastrow As Long
    
    Set ws = Sheets("Sheet1") ' Change to your sheet
    
    With ws
        lastrow = .Range("A" & .Rows.Count).End(xlUp).Row
        With .Range("B2:C" & lastrow)
            .Offset(, 4).FormulaR1C1 = "=SUMIF(C1,RC1,C[-4])"
            .Offset(, 4).Value = .Offset(, 4).Value
        End With
        With .Range("A1:A" & lastrow)
            .Offset(, 4).Value.Value = .Value
        End with
        .Range("E1:G" & lastrow).RemoveDuplicates 1, xlYes
    
    End With
    
    End Sub
    

提交回复
热议问题