Err Number = 0 End Process Runs Anyway

wsnyder

Board Regular
Joined
Sep 23, 2018
Messages
223
Office Version
  1. 365
Platform
  1. Windows
Hi,

Using Excel 365.

The err.number returns as 0, but the endproc runs anyway.
Why is that and how do I get around it?

Thanks,
-w

VBA Code:
Private Sub Get_Column_Position(ws As Worksheet)

    Dim rng As Range
    Dim arr As Variant
    Dim i As Long
    
    Set rng = ws.Range("1:1")
    arr = Array(gcsTerm_EntityCodeLife, _
                gcsTerm_DesignStart, _
                gcsTerm_PrefacStart, _
                gcsTerm_PrefacFinish, _
                gcsTerm_MoveOut, _
                gcsTerm_DSL3Finish)
                
    On Error GoTo endproc
    For i = LBound(arr) To UBound(arr)
        Select Case arr(i)
            Case gcsTerm_EntityCodeLife
                mvlposEntityCodeLife = FindColumnHeader(rng:=rng, _
                                                        SearchTerm:=gcsTerm_EntityCodeLife)
            Case gcsTerm_DesignStart
                mvlposDesignStart = FindColumnHeader(rng:=rng, _
                                                     SearchTerm:=gcsTerm_DesignStart)
            Case gcsTerm_PrefacStart
                mvlposPrefacStart = FindColumnHeader(rng:=rng, _
                                                     SearchTerm:=gcsTerm_PrefacStart)
            Case gcsTerm_PrefacFinish
                mvlposPrefacFinish = FindColumnHeader(rng:=rng, _
                                                      SearchTerm:=gcsTerm_PrefacFinish)
            Case gcsTerm_MoveOut
                mvlposMoveOut = FindColumnHeader(rng:=rng, _
                                                 SearchTerm:=gcsTerm_MoveOut)
            Case Else
                mvlposDSL3Finish = FindColumnHeader(rng:=rng, _
                                                    SearchTerm:=gcsTerm_DSL3Finish)
        End Select
    Next i
    
endproc:
    MsgBox Prompt:="Error " & Err.Number & " occurred" & vbNewLine & _
                   "In the Get_Column_Position Function" & vbNewLine & _
                   "Please check spelling of headers on the schedule sheet.", _
            Title:="Find Error", _
            Buttons:=vbOKOnly
    Exit Sub

    'Tidy up
        'Destroy objects
            Set rng = Nothing
    

End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Everything after endproc will run every time you run this code, if you don't want that to happen add Exit Sub immediately before it.
 
Upvote 0
Solution
Thanks Norie,

I had Exit Sub on the wrong line.
I moved it up before endproc:
Now works as expected.

Thanks,
w
 
Upvote 0

Forum statistics

Threads
1,214,634
Messages
6,120,659
Members
448,975
Latest member
sweeberry

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