Cancel button in Inputbox method

M

MiRa

Hi everybody,
when I use Inputbox method with Type : = 8 (Set MyObject = Input....) and I
click on Cancel button, I will get an error.
Is there any way to avoid this without On Error Goto Label ?

Thanks for answer.

MiRa
 
C

Chip Pearson

MiRa,

Try something like the following:

Dim Rng As Range
On Error Resume Next
Set Rng = Application.InputBox("select", Type:=8)
On Error GoTo 0
If Rng Is Nothing Then
MsgBox "You clicked Cancel"
Else
MsgBox "You selected: " & Rng.Address
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
K

keepitcool

Mira,

no, you'll have to prevent the error when the inputbox is cancelled.


Sub inputtest()
Dim rngVariable As Range
On Error Resume Next
Set rngVariable = Application.InputBox(prompt:="Range?", Type:=8)
On Error GoTo 0

If rngVariable Is Nothing Then
'user cancelled
Else
MsgBox rngVariable.Address
End If

End Sub

keepITcool

< email : keepitcool chello nl (with @ and .) >
< homepage: http://members.chello.nl/keepitcool >
 

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