Error Handler not activating

ndsutherland

Active Member
Joined
Jan 30, 2015
Messages
384
Code:
Private Sub InventoryList_LostFocus()
Dim i As Range
If ActiveSheet.Name = "Order Form" Then
    For Each i In ActiveSheet.Range("F2:F" & ActiveSheet.Range("F" & Rows.Count).End(xlUp).Row)
        On Error GoTo Other
        Cells(i.Row, 5) = Sheets("Inventory").Range("A" & WorksheetFunction.Match(i, Sheets("Inventory").Range("C:C"), 0))
        Cells(i.Row, 7) = Sheets("Inventory").Range("D" & WorksheetFunction.Match(i, Sheets("Inventory").Range("C:C"), 0))
        Cells(i.Row, 8) = Sheets("Inventory").Range("F" & WorksheetFunction.Match(i, Sheets("Inventory").Range("C:C"), 0))
        GoTo Either:
Other:
        On Error GoTo 0
        On Error GoTo ErrExit
[COLOR=#ff0000]        Cells(i.Row, 5) = Sheets("Other").Range("A" & WorksheetFunction.Match(i, Sheets("Other").Range("C:C"), 0))[/COLOR]
        Cells(i.Row, 7) = Sheets("Other").Range("D" & WorksheetFunction.Match(i, Sheets("Other").Range("C:C"), 0))
        Cells(i.Row, 8) = Sheets("Other").Range("F" & WorksheetFunction.Match(i, Sheets("Other").Range("C:C"), 0))
Either:
        Cells(i.Row, 1) = "SO-00000000"
        Cells(i.Row, 2) = "TBD"
    Next i
End If
ErrExit:
End Sub

My GoTo Other works just fine, but my code breaks (if match isn't found) on the highlighted line. What am I doing wrong?
code break setting set to "break on unhandled error" (I have tried "break in class module", not sure what that means, but it still doesn't work)
InventoryList is an ActiveX Comb Box
 
Last edited:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Perhaps, without On Error.
Code:
Private Sub InventoryList_LostFocus()
Dim i As Range
Dim Res As Variant

    If ActiveSheet.Name = "Order Form" Then
        For Each i In ActiveSheet.Range("F2:F" & ActiveSheet.Range("F" & Rows.Count).End(xlUp).Row)

            Res = Application.Match(i, Sheets("Inventory").Range("C:C"), 0)
            If Not IsError(Res) Then
                Cells(i.Row, 5) = Sheets("Inventory").Range("A" & Res)
                Cells(i.Row, 7) = Sheets("Inventory").Range("D" & Res)
                Cells(i.Row, 8) = Sheets("Inventory").Range("F" & Res)
            Else
                Res = Application.Match(i, Sheets("Other").Range("C:C"), 0)
                If Not IsError(Res) Then
                    Cells(i.Row, 5) = Sheets("Other").Range("A" & Res)
                    Cells(i.Row, 7) = Sheets("Other").Range("D" & Res)
                    Cells(i.Row, 8) = Sheets("Other").Range("F" & Res)
                Else
                    Cells(i.Row, 1) = "SO-00000000"
                    Cells(i.Row, 2) = "TBD"
                End If
            End If

        Next i
    End If

End Sub
 
Upvote 0
Excel kept crashing when I used Norie's code, so I went back to my original but changed "On Error GoTo 0" to "On Error GoTo -1" to clear the error, and it works perfectly. Norie, I did keep your Res idea to only match 2X instead of 6X. Thanks.
 
Upvote 0

Forum statistics

Threads
1,213,506
Messages
6,114,025
Members
448,543
Latest member
MartinLarkin

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