View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dick Kusleika Dick Kusleika is offline
external usenet poster
 
Posts: 179
Default endless loop help

John wrote:
I want to copy values on one page and paste them onto another.
Sometimes my find should find only one entry, other times it should
find a few... either way I am stuck since I added the loop command.
Not real familiar with how the DO and LOOP commands work. here is
the code... can someone tell me why I am in an endless loop

On Error Resume Next
Set rngFound = rngToSearch.find(what:=wks.Range("z1").Value,
LookIn:=xlValues, lookat:=xlWhole)

If rngFound Is Nothing Then
MsgBox "error"
Else
Do
rngFound.Resize(1, 4).Copy
wks.Select
Range("j9").Select
'Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial xlPasteValues
Loop Until rngFound.Value < rngFound.Offset(1, 0).Value
'If rngFound.Value = rngFound.Offset(1, 0) Then
Set rngFound = rngToSearch.FindNext
'Else
'GoTo ender:
'End If


John: The Find method keeps finding as long as there is something to find.
That is, it loops back to the first found cell. You need to save the
address of the first found cell, then include a test in your Loop statement
to see when you get back there. See here

http://www.dicks-blog.com/archives/2...e-find-method/

--
Dick Kusleika
MVP - Excel
Daily Dose of Excel
http://www.dicks-blog.com