Find duplicates in a column and add their corresponding values from another column

前端 未结 5 698
面向向阳花
面向向阳花 2020-12-22 08:11

I have column A with staff ids and hours worked in column K.

I would like if a staff id appears more than once to add hours worked and put the result in another colu

5条回答
  •  臣服心动
    2020-12-22 08:55

    Here is the solution for the data table located in range A1:B10 with headers and results written to column C.

    Sub Solution()
    
    Range("c2:c10").Clear
    
    Dim i
    For i = 2 To 10
    
        If WorksheetFunction.SumIf(Range("A1:a10"), Cells(i, 1), Range("C1:C10")) = 0 Then
    
            Cells(i, "c") = WorksheetFunction.SumIf( _
                             Range("A1:a10"), Cells(i, 1), Range("B1:B10"))
        Else
            Cells(i, "c") = 0
        End If
    Next i
    
    End Sub
    

提交回复
热议问题