On error goto not working

pulsecoding

New Member
Joined
May 26, 2011
Messages
31
hi all,

I am using xp office.

below code is showing error " run time error 91: object variable or with block variable not set.

Code:
On Error GoTo stop1:

start_to_be_copy = ActiveWorkbook.Sheets("Collated cases").Range("a4:a65000").Find(p).Row
end_of_copy = ActiveWorkbook.Sheets("Collated cases").Range("a4:a65000").Find(p, SearchDirection:=xlPrevious).Row

stop1:
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi

Don't use On Error in this instance, use object variables to set references to the sought values:

Code:
Dim r1 As Range, r2 As Range

Set r1 = ActiveWorkbook.Sheets("Collated cases").Range("a4:a65000").Find(p)

If Not r1 Is Nothing Then
  Set r2 = ActiveWorkbook.Sheets("Collated cases").Range("a4:a65000").Find(p, After:=r1,SearchDirection:=xlPrevious)
  start_to_be_copy = r1.Row
  end_of_copy = r2.Row
  'rest of code

Else
  MsgBox p & " not found in specified range!"
End If
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,424
Members
452,914
Latest member
echoix

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top