View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
WhytheQ WhytheQ is offline
external usenet poster
 
Posts: 246
Default Fastest way to find item in an array.

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