Do Until Loop strange behavior
Hi,
I've written a Do Until loop that looks at whether a cell contains any info.
The Do until begins:
Do Until cells(X, 2) = ""
The problem is the loop when left to run stops half way through. However if
you step through it works fine.
Heres the loop code for info
Can anyone explain to me how to stop this behavior?
X = 6
Do Until Cells(X, 2) = ""
On Error GoTo ErrHand2
Sheets("SRS").Select
Set WTBFIND = Nothing
Set addrow = Nothing
WTBFIND = Cells(X, 4)
If WTBFIND < "" Then
addrow = "C"
If InStr(1, Cells(X, 2), "Yard") Then
addrow = Yard
Else
If InStr(1, Cells(X, 2), "Direct") Then
addrow = Direct
End If
End If
Sheets("wtb").Select
Cells.Find(what:=WTBFIND, After:=ActiveCell, LookIn:=xlValue,
LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False) _
.Activate
addcol = ActiveCell.Row
If addrow = "C" Then
Results = Cells(addcol, Yard) + Cells(addcol, Direct)
Else
Results = Cells(addcol, addrow)
End If
Else
Results = "0"
End If
ErrHan2: Sheets("SRS").Cells(X, 13) = Results
X = X + 1
Loop
Sheets("Srs").Select
Exit Sub
ErrHand2:
Results = "0"
Resume ErrHan2
End Sub
|