View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default FIND method , versus FOR EACH ...

The find function uses the setting that are found in the find dialog. Since
the end user can change these settings you should always explicitly set these
when you use the function. That being said you set all of the required
settings for the question at hand. You don't really want to be overwritting
settings that do not affect the ability of your code to do it's job, so in
your case things like the search direction should not be set.

As for Andy's difficulty using Find if you use it correctly it works every
time. I have used it litterally hundreds of times with complete success. The
biggest difficulties that I see are people not explicitly setting all of the
required parameters correctlyu and not setting the return value to a range
object.

My only issue with the find function is that I can not read the parameter of
the find prior to changing them. Generally speaking I always try to put
things back the way I found them. The end user should not be able to see any
side effects to running my code. Since I can not read the values prior to
changing them, I can not return the settings back to their original values.
This means that the next time the end user uses the find function they will
see my prameters and not the ones they set. It's a minor thing but...
--
HTH...

Jim Thomlinson


"Joel" wrote:

The VBA Find dialog will inherit the worksheet setting, I didn't think the
Find function would.

"andy the pugh" wrote:

On May 29, 8:27 am, ytayta555 wrote:
A good day

I want to use FIND method instead my
old FOR EACH method in my code , I
think (and I have read) it will work faster .


I recently switched the other way. Find stopped working for me for
some reason in a praticular workbook (both in VBA _and_ in the find
dialog), so I changed to a For Each... version.

Find inherits the search parameters from the last search done by the
user in the Find dialog, unless you specifically set all the options.
Even then it seems to sometimes get in a tangle and not do the search
you are looking for. If you use For Each then you know exactly where
you are looking and exactly how you are matching. it might be slower,
but it seems better controlled.