Loop

R

ranswert

Will this get in a continual loop if "a" never equals "linkno"?

With rng
Set xcell = .find(what:=drwno, LookIn:=xlValues,
LookAt:=xlWhole, _
SearchOrder:=xlByColumns)
a = xcell.Offset(0, 10).Value
MsgBox ("a = " & a)
If a <> linkno Then
Do
Set xcell = .FindNext(xcell)
a = xcell.Offset(0, 10).Value
Loop While a <> linkno
End If
End With
Thanks
 
J

Jim Rech

Will this get in a continual loop

Looks like it. What you want to do with the Find method is stop when you're
back to the first hit, since Excel will just keep finding the same cells.
So get the address of the first hit and then break out of the loop if a =
linkno or the address of xcell = the address of the first hit.

--
Jim
| Will this get in a continual loop if "a" never equals "linkno"?
|
| With rng
| Set xcell = .find(what:=drwno, LookIn:=xlValues,
| LookAt:=xlWhole, _
| SearchOrder:=xlByColumns)
| a = xcell.Offset(0, 10).Value
| MsgBox ("a = " & a)
| If a <> linkno Then
| Do
| Set xcell = .FindNext(xcell)
| a = xcell.Offset(0, 10).Value
| Loop While a <> linkno
| End If
| End With
| Thanks
 
R

ranswert

Thanks I'll give that a try

Jim Rech said:
Looks like it. What you want to do with the Find method is stop when you're
back to the first hit, since Excel will just keep finding the same cells.
So get the address of the first hit and then break out of the loop if a =
linkno or the address of xcell = the address of the first hit.

--
Jim
| Will this get in a continual loop if "a" never equals "linkno"?
|
| With rng
| Set xcell = .find(what:=drwno, LookIn:=xlValues,
| LookAt:=xlWhole, _
| SearchOrder:=xlByColumns)
| a = xcell.Offset(0, 10).Value
| MsgBox ("a = " & a)
| If a <> linkno Then
| Do
| Set xcell = .FindNext(xcell)
| a = xcell.Offset(0, 10).Value
| Loop While a <> linkno
| End If
| End With
| Thanks
 
R

Rick Rothstein \(MVP - VB\)

Just to make a point... it took 1 hour 6 minutes for you to get an answer to
your question and another 34 minutes after that for you to see that answer.
You could have gotten an instaneous answer to your question if you had
placed your cursor on the word FindNext in your code and pressed F1 to evoke
Help for it... the Help file that would have come up for this method
explains the problem you raised in its Remarks section and gives a code
example on how to get around the problem.

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

find 2
error 5
Listbox problem agaie 3
Listbox problems 3
intersect 12
Match style 0
Placing the MsgBox "No ID found" statement in my code?? 12
Need help with correct syntax please 2

Top