InputBox Cancel event

R

Rafi

I have the following code prompting the user to select a range.

Set rng = Application.InputBox(Msg1, Title1, Type:=8)

I need to be able to trap both a CANCEL event as well as when the user
clicks "OK" without selecting a range.
 
C

Chip Pearson

Try something like

Dim R As Range
On Error Resume Next
Set R = Application.InputBox(prompt:="Enter", Type:=8)
If R Is Nothing Then
Debug.Print "cancelled"
Else
Debug.Print "selected: " & R.Address
End If

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 

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

Similar Threads


Top