+ Reply to Thread
Results 1 to 4 of 4

Count Duplicates from VBA Array?

Hybrid View

  1. #1
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Count Duplicates from VBA Array?

    No, not really. Here's a late bound version if you don't want to add the reference...
    Sub foo()
        Dim sarrCodes(0 To 5) As String
        Dim a As Long
        Dim vKey As Variant
        Dim objDic As Object   
     
        sarrCodes(0) = "ISB2-01"
        sarrCodes(1) = "ISB2-01"
        sarrCodes(2) = "ISB2-02"
        sarrCodes(3) = "ISB2-02"
        sarrCodes(4) = "ISB2-02"
        sarrCodes(5) = "ISB2-03"
        
        Set objDic = CreateObject("Scripting.Dictionary")
        
        For a = LBound(sarrCodes) To UBound(sarrCodes)
            If objDic.Exists(sarrCodes(a)) Then
                objDic.Item(sarrCodes(a)) = objDic.Item(sarrCodes(a)) + 1
            Else
                objDic.Add sarrCodes(a), 1
            End If
        Next a
        
        For Each vKey In objDic.Keys
            Debug.Print vKey; objDic.Item(vKey)
        Next vKey
        
    End Sub
    Last edited by Colin Legg; 03-06-2011 at 09:18 PM.
    Hope that helps,

    Colin

    RAD Excel Blog

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1