View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
Zack Barresse Zack Barresse is offline
external usenet poster
 
Posts: 124
Default Can .FindNext return Nothing??

There would be no need to test for it inside of the loop. That's why it's
kept as the loops *condition* to be in it's running/looping state. That's
like trying to figure out which came first, the egg shell or the chicken..
it does make a man think though ..

So you've established that the Range Object can in fact be Nothing if there
are no more of the search/Find values left in the range to search in, in
other words they have all been modified in some fashion. The other thing
you need to make certain of is that Find/FindNext will (by default) start
from the upper-left portion of the range to search.

So both checks, for Is Nothing and if the .Address < FirstAddress (barring
it's been set), are necessary for a complete check and to cover all your
bases.

The only other question may be would you use ...

Do Until c.Address = fAddy Or c Is Nothing
'...
Loop

... or..

Do
'...
Loop Until c.Address = fAddy Or c Is Nothing

I recommend you try each one for yourself. You will see that in one of
these, it will look at both the Do and the Loop lines, and the other one
will only look at the Do line on the first iteration.

Good thread. :)

--
Regards,
Zack Barresse, aka firefytr


"Wild Bill" wrote in message
.. .
Ah, very astute of you to pick that up! So c indeed could become
Nothing if c.Value is modified. Way to go! You're definitely underpaid
for what you do here :-O

It also occurred to me that break mode (i.e., stopping in Debug window)
could allow an action to result in a FindNext failure(e.g. changing
ActiveSheet), but I felt that the Nothing test in their example should
not have been written to contemplate that. Only real men would step
code, right, and they ought to be big enough to deal with such
consequences on their own time!

Now going beyond my original question, as you have established that
Nothing indeed is possible: as to kablewie, so much for left to right
evaluation in VBA - NOT! Boo! Shame on them! And since that happens, are
you saying that thus it is useless to test a range (cell) c for Is
Nothing, when c.address is in the same If? So their example should have
tested for nothing inside the loop and Exit Do, and let the While only
test the .Address?

On Fri, 29 Apr 2005 20:37:12 -0500, Dave Peterson
wrote:

Actually, I think the xl2003's help has the opposite bug that you
describe.

I think that it won't wraparound to the first cell. The sample code is
looking
for "2" and changes it to "5". So after it gets all the 2's, the
.findnext will
return nothing.

And that causes a blowup in this portion:

Loop While Not c Is Nothing And c.Address < FirstAddress

Since c is nothing, c.address doesn't make sense (and kablewie!!!).