Help with on error goto

nehpets12

Active Member
Joined
Feb 22, 2002
Messages
453
In this code I have to Error Traps the first On Error GoTo 1 the second On Error GoTo 2 Why does this come up with an error I have not set up any DIM statements could this be the cause of the error code runtime error 91


Rich (BB code):
Sub Find_Chassis_No()


    On Error GoTo 1
    Application.ScreenUpdating = False
    Application.CutCopyMode = False
    MyReg = Range("C18").Value
    Sheets("Allmachines Copy").Select
    Columns("M:M").Select
    Selection.Find(What:=MyReg, After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    MyWK = Format(ActiveCell.Offset(0, -11).Value, "")


1   If MyWK > 0 Then GoTo 2
    On Error GoTo 2
    Sheets("Registration Numbers").Select
    Columns("G:G").Select
    Selection.Find(What:=MyReg, After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    MyID = ActiveCell.Offset(0, -3).Value
    Columns("A:A").Select
    Selection.Find(What:=MyID, After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    MyWK = Format(ActiveCell.Offset(0, 1).Value, "")




2   Range("A1").Select
    Sheets("Details").Select
    Range("B7").Value = MyWK
    Range("C18").Value = ""
    Range("C18").Select
    Application.ScreenUpdating = True
End Sub
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
Stephen

Why use On Error/GoTo in the first place?

If as I suspect the reason for the error(s) is that nothing is being found why not check that?

For example.
Code:
Dim rngFnd As Range

    Application.ScreenUpdating = False
    Application.CutCopyMode = False
    MyReg = Range("C18").Value
    Set rngFnd = Sheets("Allmachines Copy").Columns("M:M").Find(What:=MyReg, After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
        
    If Not rngFnd Is Nothing Then MyWK = Format(rngFnd.Offset(0, -11).Value, "")
PS What's the purpose of the Format?:eek:
 

nehpets12

Active Member
Joined
Feb 22, 2002
Messages
453
Thank you for your quick response :)

you are correct I was only using the on error was that the data was not found I was not sure how to set it up to find nouthing, this has helped enormously thank you

The reason for the format was that the data it was searching was 004285
but I only wanted to copy it as a number ie 4285
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
Stephen

Well if you wanted a number you wouldn't use Format.:)

As far as I'm aware Format returns string values.

Try Val or CInt or CLng.
 

nehpets12

Active Member
Joined
Feb 22, 2002
Messages
453
When I run your sample code I get a run time error 13 type mismatch Help please :)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,469
Messages
5,596,329
Members
414,055
Latest member
mcarduner

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
Top