+ Reply to Thread
Results 1 to 4 of 4

Count Duplicates from VBA Array?

  1. #1
    Registered User
    Join Date
    01-14-2011
    Location
    Manitoba
    MS-Off Ver
    Excel 2007
    Posts
    10

    Question Count Duplicates from VBA Array?

    Hi.

    I currently have an array and I want to count the number of duplicates in this array, but I'm not sure exactly the best approach for this.

    Current Array
    Array: arry(i,count)

    arry(1,count) = 'ISB2-01"
    arry(2,count) = 'ISB2-01"
    arry(3,count) = 'ISB2-02"
    arry(4,count) = 'ISB2-02"
    arry(4,count) = 'ISB2-02"
    arry(5,count) = 'ISB2-03"

    New Array Result (this is what I want to end up with)

    newarry(string,count) = newarry("ISB2-01",2)
    newarry(string,count) = newarry("ISB2-02",3)
    newarry(string,count) = newarry("ISB2-03",1)


    I know this is pretty easy but I can't rap my head around it to get this.

  2. #2
    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?

    Hi,

    You could consider using a dictionary object to do this. For example:
    Please Login or Register  to view this content.
    Results in immediate window:
    Please Login or Register  to view this content.
    This example uses early binding so it requires a reference to the Microsoft Scripting Runtime library.
    Last edited by Colin Legg; 03-06-2011 at 09:18 PM.
    Hope that helps,

    Colin

    RAD Excel Blog

  3. #3
    Registered User
    Join Date
    01-14-2011
    Location
    Manitoba
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Count Duplicates from VBA Array?

    Is there any downfall with using this MS reference?

  4. #4
    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...
    Please Login or Register  to view this content.
    Last edited by Colin Legg; 03-06-2011 at 09:18 PM.

+ 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