View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Adam Adam is offline
external usenet poster
 
Posts: 287
Default Do loop error while using FindNext command

I am haveing stange bugs when I use the following code. If I step trough
line by line with the "F8" key the code will execute however if you just run
it normally it will bring up and error messge saying "Code execution has been
interupted"

If I click continue the code will break each time though the main loop but
give the correct results.

Below is a simplified version of my code. In my full program the i is not
what i'm matching there is actually an array variable that I index using i
[ex .find(what:=myArray(i))] but the problem loop is structured the same.

Any suggestions would be appreciated thanks.

Code:
Public Sub Sample()
Set c = Worksheets(1).Fange("A2")
For i = 1 To 100

Set c = Worksheets(1).Columns(1).Find(What:=i, After:=c,
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByColumns,
SearchDirection:=xlNext)
If Not c Is Nothing Then
tempaddress = c.Address
tempRowStart = Range(tempaddress).Row
tempCount = 0
MsgBox tempRowStart
Do
Set c = Worksheets(1).Columns(1).FindNext(c)
tempCount = tempCount + 1
tempRowStop = tempRowStart + tempCount - 1
Loop While Not c Is Nothing And c.Address <
tempaddress
End If
Next

End Sub