I have 8 pairs of data sets.
Each pair is comprised of a 1-dimensional array with typically 400 string elements and a column with typically 2000 string elements.
Within each pair of data sets, I want to check each element of the array against each element of the column for a match.
The simplified version of my approach:
For i = 1 to 8
For j = 0 to 400
For k = 0 to 2000
If Cells(k,i) = myArray[1, then 2, then 3, etc.](j) then [action]
next K
next j
next i
I'm looping through column A's first 2000 cells 400 times, then column B's first 2000 cells 400 times, and so on. That seems redundant and it's around 6.4 million cells checked.
The actual code. It's looking for dupes that also have a qualifying boolean. When these conditions are met, then it's taking their associated integer value and row number.
It sums all the integer values and replaces those integers with their sum.
It does this for every unique name, and then (not shown), repeats this for the remaining 7 data sets.
For i = 0 To j - 1 'starts with the first unique element and searches for dupes...
v = 0 'initial qty value
r = 0 'initial number of rows with dupes
For k = 2 To WULastRow 'go though each cell in the first column
If Cells(k, colPair + 2) = True And Cells(k, colPair).Text = uniqueNames(i) Then '...if one is found and the row's boolean is true...
v = v + Cells(k, colPair + 1).Value '...sum it's qty with previous dupes qty's...
r = r + 1 'increment number of dupes found
ReDim Preserve rngMatch(r - 1) 'increase the size of the array that will hold the row numbers of the dupes.
rngMatch(r - 1) = k '...and input dupe's row number to said array.
End If
Next k
k = 0
'if 1 or more duplicate is found for the given unique item name is found...
If r > 1 Then
k = 0
For k = 0 To r - 1
Cells(rngMatch(k), colPair + 1).Value = v '...input the summed quantity in their qty cells...
Next k
End If
Next i 'then regardless, move on to the name unique name and repeat this process.