I came up with the following algorithm, located at the end of the post, that works as intended.
My main issue, is that when iMain goes to the next iteration, it will loop through the entire inner array/collection of unique numbers, sviColl, again. I'm planning on using this in a different implementation that will contain an index of around 45 items, and 7 unique prefixes (sheet named "sheet2 orig list"). Resulting in 315 iterations. Most of which will be very redundant.
Do While q.Count <= allocatedRows And dwCounter1 <= sviColl.Count
If sviColl(sviCollIndex).impPrefix(impPrefixColl) = impPrefixColl(iMain) Then 'Will use q.Count to space out the dequeues evenly (where applicable)
q.Enqueue sviColl(sviCollIndex).sourceVeh()
End If
sviCollIndex = sviCollIndex + 1
dwCounter1 = dwCounter1 + 1
Loop
According to my calculations, implementing a solution similar to linked list, will reduce amount of iteration by up to 66%
+------------+-------------+
| Collection | Linked List |
+------------+-------------+
| 4 | 4 |
| 14 | 10 |
| 24 | 14 |
| 32 | 18 |
| 40 | 8 |
| 50 | 10 |
| 60 | 10 |
| | |
| 224 | 74 |
+------------+-------------+
I've come up with 2 possible solutions. Use a collection alternative similar to linked list, or send each index that doesn't match, impPrefixColl(iMain), to a new collection, destroy or clear old collection (Set Coll = Nothing), and rename new collection to that of the old collection.
In the case of the latter solution, it seems I may have to resort to recursion, since there doesn't seem to be a way of "renaming" a collection without resorting to for loop.
Edit: disregard the recursion
I was thinking of using a 'Dictionary', but it seems that may leave a 'zombie index' in its place, where as a linked list will remove it completely. I've been unable to find a vba linked list that comes with an example of using it.
For iMain = 1 To impPrefixColl.Count
allocatedRows = 0
sviCollIndex = 1
rowToStartFilling = prefix_SearchRng.Find(What:=impPrefixColl(iMain), LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False).Row 'Perform a search range & set it to impPrefixColl(i)
Set currentCell = myWs.Cells(rowToStartFilling, importFilePrefCell.Column)
'Count rows allocated to present prefix
Do While (currentCell.Value = impPrefixColl(iMain) Or currentCell.Value = "") And Not currentCell.Row > lastRowOfSheet
Set currentCell = currentCell.Offset(1, 0)
allocatedRows = allocatedRows + 1
Loop
dwCounter1 = 1
'Reset traversing cell to initial slot of impFilePrefix
Set currentCell = currentCell.Offset(rowToStartFilling - currentCell.Row, 0) '9 - 29 = 20
Do While q.Count <= allocatedRows And dwCounter1 <= sviColl.Count
If sviColl(sviCollIndex).impPrefix(impPrefixColl) = impPrefixColl(iMain) Then 'Will use q.Count to space out the dequeues evenly (where applicable)
q.Enqueue sviColl(sviCollIndex).sourceVeh()
End If
sviCollIndex = sviCollIndex + 1
dwCounter1 = dwCounter1 + 1
Loop
dwCounter1 = 1
Do While q.Count > 0 And dwCounter1 <= allocatedRows
currentCell.Offset(, sourceVehCell.Column - importFilePrefCell.Column).Value = "'" & q.Dequeue
'currentCell.HorizontalAlignment = xlLeft 'Issues with 'CreatObject Queue'
Set currentCell = currentCell.Offset(1, 0)
dwCounter1 = dwCounter1 + 1
Loop
dwCounter1 = 1
q.Clear
Next iMain
The sheet name is the first listed, ImpSveh. The module is, Module 5.
Bookmarks