On error resume next

H

Hennie Neuhoff

Hi All,
The following code returns an error if the user doesn’t select a
range, with the error message "The formula you typed contains
an error."
Any assistance would be much appreciated.[Excel 2003]

Public Sub TestError()
Dim cellsSelected As Range
On Error Resume Next
Set cellsSelected = _
Application.InputBox(prompt:="Select a cell range", _
Type:=8)
On Error GoTo 0
If cellsSelected Is Nothing Then Exit Sub
End Sub
 
J

JLGWhiz

This will cure the message, but it will not let you pass the input box
without either selecting a range or clicking cancel. Give it a try.

Public Sub TestError()
Dim cellsSelected As Range
Application.DisplayAlerts = False
On Error Resume Next
Set cellsSelected = _
Application.InputBox(prompt:="Select a cell range", _
Type:=8)
If Err.Number > 0 Then
MsgBox "You did not select a range"
Exit Sub
End If
On Error GoTo 0
Application.DisplayAlerts = True
If cellsSelected Is Nothing Then Exit Sub
End Sub
 
P

Per Jessen

Hi

You have to set Excel up to break on unhandled errors only, now I
guess it break on all errors.

In the VBA editor goto Tools > Options > General > In 'Error Trapping'
section, mark ' Break on unhandled errors.

Hopes this helps.
Per
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top