How to Count Duplicate Values from two Columns or from an Array in Excel VBA

Swathi Kumar 1 Reputation point
2022-11-02T06:44:21.083+00:00

I need to count how many times the numbers have been repeated from an array.

Developer technologies Visual Basic for Applications
{count} votes

1 answer

Sort by: Most helpful
  1. Oskar Shon 866 Reputation points
    2022-11-08T19:26:25.867+00:00

    I you can use VBA to that you can add your values from range, array to collection or dictionary.
    count of it minus your values giving you a duplicate count.

    Example

    258432-image.png

    so

    258374-image.png

    and code:

    Sub ile_dubli()  
    'MVP OShon from VBAools.pl  
    Dim r As Range: Set r = Range("A1:C4")  
    Dim c As Range, col As New Collection  
    For Each c In r  
          On Error Resume Next  
          If Len(c) > 0 Then col.Add c, c  
          On Error GoTo 0  
    Next  
    Dim noEmpty&: noEmpty = Application.WorksheetFunction.CountA(r)  
    MsgBox "All cells " & noEmpty & " - " & col.Count & " unicue in collection" & _  
          " is " & noEmpty - col.Count & " as duplitates", vbInformation, "VBATools.pl"  
    End Sub  
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.