I have the following code that prompts the user to select a range of cells.
I am having difficulty checking if the range is valid (i.e. did they just enter a number into the input box?) or if they pressed cancel. How can I differentiate?
Do While (True)
Dim mInput As Range
mInput = Application.InputBox(Prompt:="Please select the cells.", Type:=8)
If (mInput Is Nothing) Then
Exit Sub
End If
If (mInputRange.Columns.Count <> 1) Then
MsgBox "There must be only one column selected.", vbOKOnly
Else
End If
Loop
Excel raises an error before the result is returned if it cannot be converted into a range. Try doing it yourself.
Also, I presume you’re already doing this but you’ll need to use
instead of
If you press cancel an error is raised also, meaning you need to use some sort of error checking routine: