Input Box Cancel Button

  • Thread starter Thread starter rickylee
  • Start date Start date
R

rickylee

Set myRange = Application.InputBox(prompt := "Sample",
type := 8)
I'm using VBA to have someone chose a cell range in an
excel program. The above statement was provided in the VBA
help menu under "input box". The input box works just fine
when you pick a cell and press OK. However this input box
also has a cancel button which returns "FALSE". As such
when you press CANCEL, the "Set" portion is looking for a
range input and it gets FALSE and gives a "type mismatch
error." Any way of fixing this??
 
Try something like the following:

Dim MyRange As Range
On Error Resume Next
Set MyRange = Application.InputBox(prompt:="Test", Type:=8)
If MyRange Is Nothing Then
' user didn't select a range
Else
' user selected a range
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Thank You Very Much! The "On Error Resume Next" plus
the "IF" statement did the trick.

RLE
 
Back
Top