Input Box - Hit cancel

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

It there not really a direct way to tell if the Cancel button was clicked of
an InputBox. I was told in an earlier posting to do something like this:

EnterState = InputBox("Enter State: ")
If EnterState <> "" Then
ActiveCell.Value = EnterState
Else
ActiveCell.Value = Null
Endif

'----But----
What I want is if the cancel is pressed don't do anything. What is
happening is if for example the current cell value is "Florida" ; and the
InputBox opens and the person puts "North Carolina" in the InputBox field and
then changes their mind and clicks Cancel, then the cell value is
erased....when it should still say "Florida"

How do you catch the Cancel key press and tell it don't do anything.

Thank you for your help.

Steven
 
Steven, try this,

EnterState = InputBox("Enter State: ")
If EnterState <> "" Then ActiveCell.Value = EnterState


--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003
 
Dim EnterState As Variant
EnterState = InputBox("Enter State: ")
If EnterState <> "" Then
ActiveCell.Value = EnterState
Else
ActiveCell.Value = Null
End If

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 
As an observation, both Paul's and Bob's solutions cause the Input Box to
display twice. Also I had to change the "" to Empty to get Bob's to work.
They both leave The active cell intact with the modification I mentioned.

Qustion for Steven: Is there a way to accomplish your goal without
overwriting the active cell. Stated differently, could you control the
conditions so that the user would not have to make the decision to cancel and
thereby eliminate the problem?
 
Neither one causes the inputbox to display twice if run as written.

But Bob's clears the cell on cancel if run as written.

Believe he meant

Sub bBB()
Dim EnterState As Variant
EnterState = InputBox("Enter State: ")
If EnterState <> "" Then
ActiveCell.Value = EnterState
End If
End Sub
 

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

Cancel Input Box error 16
Input Box Cancel function 4
Application.InputBox 2
Cancel InputBox 6
Input Box 2
Input box cancel 1
Input box cancel produces error 5
using variable from input box 3

Back
Top