Fastest way to find item in an array.
Hi J,
Try something like:
For i = 1 To 600
With Cells(i, 1)
If Not IsError(Application.Match(.Value, myArray, 0)) Then
'do something, e.g:
.Interior.ColorIndex = 6
End If
End With
Next i
---
Regards,
Norman
"WhytheQ" wrote in message
oups.com...
I have an array of 40 items.
I need to go down a column of 600 cells and for each cell I need to
test whether the cell.value is equel to any of the items in the array.
At present this is really slow as my code is doing a loop of 40, 600
times (i.e 24,000).
The loop looks something like:
For i= 1 to 600
myVal = cells(i,1)
For j = 1 to 40
if myVal = myArray(j) then blah blah
next j
next i
Would I have been better using a collection rather than an array?
Is an array the best choice?
Any help greatly appreciated,
J
|