I have a macro that searches and copies some date from one sheet back into another, if that value is found, and repeats for every row that's not blank.
In my current document, of around 150 rows, the following macro runs fine, but randomly throws up the error:
Run-time error '91': Object variable or With block variable not set
This is the macro:
Sub Update()
Application.ScreenUpdating = False
Application.CutCopyMode = False
Application.StatusBar = "Cleaning New Roles..."
Sheets("new").Select
Range("A2").Select
Do Until IsEmpty(ActiveCell)
Dim SearchValue As String
SearchValue = ActiveCell.Value
Sheets("Old").Select
On Error GoTo Error_handler
Cells.Find(What:=SearchValue, SearchOrder:=xlByRows, SearchDirection:=xlNext, SearchFormat:=False).Activate
Range("R" & Selection.Row & ":T" & Selection.Row).Select
Selection.Copy
ActiveCell.Offset(0, -1).Select
Sheets("new").Select
Range("R" & Selection.Row).Select
Selection.PasteSpecial Paste:=xlPasteValues
Error_handler:
Sheets("new").Select
Range("A" & Selection.Row).Select
ActiveCell.Offset(1, 0).Select
Loop
Application.ScreenUpdating = True
Application.StatusBar = False
End Sub
The debug highlights the Cells.Find
row.
I can't see why the first 100 rows are OK and then it breaks.
Any guidance would be very helpful.