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

前端 未结 5 695
面向向阳花
面向向阳花 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:37

    Sub SelectColoredCells()
        Dim rCell As Range
        Dim lColor As Long
        Dim rColored As Range
    
        'Select the color by name (8 possible)
        'vbBlack, vbBlue, vbGreen, vbCyan,
        'vbRed, vbMagenta, vbYellow, vbWhite
        lColor = RGB(156, 0, 6)
    
        'If you prefer, you can use the RGB function
        'to specify a color
        'Default was lColor = vbBlue
        'lColor = RGB(0, 0, 255)
    
        Set rColored = Nothing
        For Each rCell In Selection
            If rCell.Interior.Color = lColor Then
                If rColored Is Nothing Then
                    Set rColored = rCell
                Else
                    Set rColored = Union(rColored, rCell)
                End If
            End If
        Next
        If rColored Is Nothing Then
            MsgBox "No cells match the color"
        Else
            rColored.Select
            MsgBox "Selected cells match the color:" & _
                vbCrLf & rColored.Address
        End If
        Set rCell = Nothing
        Set rColored = Nothing
    End Sub
    

    this highlights the duplicates

提交回复
热议问题