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

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

    Below code identifies duplicate value in a column and highlight with red. Hope this might be of some help.

      iLastRow = Cells(chosenExcelSheet.Rows.Count, 1).End(xlUp).Row 'Determine the last row to look at     
        Set rangeLocation = Range("A1:A" & iLastRow)
    
        'Checking if duplicate values exists in same column
            For Each myCell In rangeLocation
                If WorksheetFunction.CountIf(rangeLocation, myCell.Value) > 1 Then
                    myCell.Interior.ColorIndex = 3'Highlight with red Color
                Else
                    myCell.Interior.ColorIndex = 2'Retain white Color
                End If
            Next
    

提交回复
热议问题