Thread: Loop Error Trap
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
mburkett mburkett is offline
external usenet poster
 
Posts: 23
Default Loop Error Trap

I am getting an error in the code below after the first loop though IF
there is an error in finding the value in the worksheet. The first
loop though works correctly. Here is the error: Run-time error '91'
Object variable or With block variable not set

X = 0
Do Until X = pdatecnt2

Range("a1").Select
ActiveCell.Offset(X, 0).Range("A1").Select
accttodel = Selection.Value
aSheet.Activate
Range("a1").Select
Range("A:A").Select
On Error GoTo nextx
'The error occurs in the following line
Selection.Find(What:=accttodel, After:=ActiveCell,
LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False).Activate

ActiveCell.Rows("1:1").EntireRow.Select
Selection.Delete Shift:=xlUp
nextx:
Sheets("temp").Select

X = X + 1
Loop


Thank you for taking a look -Michael