Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Speed up Array Transfer to Dictionary
Hi I have a routine which checks an array with duplicate entries and tranfers
only the unique items to a dictionary. The code works fine excpet it is very slow. Its slow because the array has to compare each of its element to every other element in the array. If the size of the array is large, the code slows down dramatically. The array is called PR2 and the Dictionary is called Dict1. Note I need all the duplicates as I use them to calculate a frequency of occurence for each duplicate. This is why I kept the duplicate data in an array in the first place as a dictionary cannot have duplicate keys. Set Dict1 = New Dictionary For t = LBound(PR2) To UBound(PR2) If Not Dict1.Exists(PR2(t)) Then For z = LBound(PR2) To UBound(PR2) If z = t Then 'Do nothing as you are comparing this 'word to itself ElseIf z < UBound(PR2) Then If PR2(t) = PR2(z) Then 'Duplicate flagged. Don't add to 'Dictionary dupe = dupe + 1 End If Else 'Only add to dictionary on last 'run as dictionary can not have duplicate 'keys Dict1.Add PR2(t), dupe End If Next End If 'Reset Duplicate dupe = 1 Next Thanks EM |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Improve speed of data transfer loop | Excel Programming | |||
Speed of fixed array versus dynamic array | Excel Programming | |||
Please Help: Transferring from Dictionary to Array | Excel Programming | |||
HOW TO TRANSFER AUTOCORRECT DICTIONARY TO NEW COMPUTER?? | Setting up and Configuration of Excel | |||
Speed up performance for very big array | Excel Programming |