On Error Resume Next interfering with Err.Number?

gravanoc

Active Member
Joined
Oct 20, 2015
Messages
346
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I have a variant variable that will store the user's response to an InputBox in which they are supposed to choose a range or press Cancel. Since Cancel makes the variable False, the Set statement could cause an error, so I use On Error Resume Next before the assignment statement, and then follow it on the next line with On Error GoTo 0. The problem occurs when I try to check Err.Number with an If statement (If Err.Number = 13 Then) since it always returns False. However, if I instead put On Error GoTo NextBlock in place of On Error Resume Next, it will properly recognize Err.Number in an If statement.

Is there a better way to do this?

Code:

VBA Code:
       On Error GoTo -1
       On Error GoTo ErrNext
       Set answer = Application.InputBox(Prompt:="Please select the cell with key phrase " & successfulAttempt & " in it, i.e. Problemes constates par le Client." _
                 & "  If there are not hyphens (-) before each item, press Cancel.  If the sheet is blank select A1.", Title:="Manual Select", Type:=8)
       On Error GoTo 0
                    
       If Err.Number = 13 Then  ' I could put ErrNext before this if statement if I wanted to and it would work correctly
ErrNext:
                        
                  On Error GoTo -1
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
You could do it like
VBA Code:
       Dim Answer As Range
       On Error Resume Next
       Set Answer = Application.InputBox(Prompt:="Please select the cell with key phrase " & successfulAttempt & " in it, i.e. Problemes constates par le Client." _
                 & "  If there are not hyphens (-) before each item, press Cancel.  If the sheet is blank select A1.", Title:="Manual Select", Type:=8)
       On Error GoTo 0
                    
       If Answer Is Nothing Then
         'do something
       End If
 
Upvote 0
Solution

Forum statistics

Threads
1,214,424
Messages
6,119,407
Members
448,894
Latest member
spenstar

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