Write a VBA code that removes duplicates from only cells that are highlighted?

 Question:

  I would like to only remove duplicates of cells that are highlighted (in yellow). I was wondering if it is possible to do that.




 Answers:
 
Say we have a column of values, some of which are hi-lighted in yellow. Say the column contains duplicates. For example:
enter image description here
This macro will examine the yellow cells and remove duplicates:
Sub TheKingInYellow()
    Dim N As Long, i As Long, wf As WorksheetFunction
    N = Cells(Rows.Count, 1).End(xlUp).Row
    Set wf = Application.WorksheetFunction
    For i = N To 2 Step -1
        With Cells(i, 1)
            v = .Value
            c = .Interior.ColorIndex
            If wf.CountIf(Range(Cells(i - 1, 1), Cells(1, 1)), v) > 0 And c = 6 Then
                .Delete
            End If
        End With
    Next i
End Sub
Here is the result:
xx



Commentaires

Posts les plus consultés de ce blog

XAJAX with PHP – The future of web development

XAJAX with PHP – The future of web development

Database connection pooling in ADO.Net