View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Fastest way to find item in an array.

You might look carefully again at Charles' suggestion in full, in particular
first putting cell values into an array rather than looping cells.

dim myVals as variant
myVals=the600Cells

Would need to test but I'd be surprised if your Match function works faster
than looping the array.

If you are repetitively searching the same array better first to sort it,
then there are faster methods for searching it.

Regards,
Peter T

"WhytheQ" wrote in message
ups.com...
Charles,
Thanks for contribution but I think your code is still potentially
going to be looping round i 600 times and for each i there will be 40
j's : in other words 24,000 executions.
Looking at other posts the below code:
For j = 1 to 40
if myVals(i,1) = myArray(j) then blah blah EXIT FOR
next j
could be replaced by:
If Not IsError(Application.Match(.Value, myArray, 0)) Then
'do something
End If
and might be a bit quicker

anyway....thanks everyone!loads of ideas
J