application.inputbox

  • Thread starter Thread starter Murat
  • Start date Start date
M

Murat

Hi,

When i run following program and press Cancel button, Error Code: 424
occurs.

Dim aralik As Range
Set aralik = Application.InputBox(prompt:="Select range:", Type:=8)

How can i check that the cancel button was pressed?
 
Hello Murat
Dim aralik As Range
On Error Resume Next
Set aralik = Application.InputBox(prompt:="Select range:", Type:=8)
If Err Then
MsgBox "You pressed cancel"
End If

HTH
Regards
Pascal
 
Hi
try

Sub foo()
....
Dim aralik As Range
On Error Resume Next
Set aralik = Application.InputBox(prompt:="Select range:", Type:=8)
If Err <> 0 Then
Exit Sub
End If
On Error GoTo 0
' your code
....
End Sub
 
Murat,

The problem is being caused by the Set statement, there is nothing to set
when Cancel is hit. In this sort of instance, you have to manage the
situation yourself, trap the error and respond to that.

To trap the error, use On Error Resume Next. Check help for details.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Back
Top