InputBox

S

Sandy

Hi
I have the following inputbox which returns a range selected by the user.

Set rRange = Application.InputBox(Prompt:="Please select any entry within "
_
& vbCrLf & "the row you would like to amend.", _
Title:="Select a row", Type:=8)

If however the user selects nothing and then clicks ok, an error box pops
up:-
"The formula you have typed contains an error etc".
Is it possible to have an alternative message box pop up which
would say something like - "You have not made a selection, please
try again!."
I could then redirect to the inputbox, by way of a goto.

I hope I am making sense.

Sandy
 
J

john

Sandy,
try this:

Sub RangeData()
Dim rRange As Range

On Error Resume Next

Application.DisplayAlerts = False

Set rRange = Application.InputBox _
(Prompt:="Please select any entry within " _
& vbCrLf & "the row you would like to amend.", _
Title:="Select a row", Type:=8)


On Error GoTo 0

Application.DisplayAlerts = True

If rRange Is Nothing Then

Debug.Print "cancelled"

Exit Sub

Else

rRange.Value = "OK"

End If

End Sub

Note the use of both, On Error Resume Next and Application.DisplayAlerts =
False. These stop Excel from trying to handle any bad input from the user, or
if they Cancel.

Hope helpful
 

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