Application.InputBox

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

Guest

I have the following code:

vAmount = ActiveCell.Value
Dim EnterAmount As Variant
EnterAmount = InputBox("Enter the amount to Hardcode: ", , vAmount)
If EnterAmount <> "" Then
ActiveCell.Value = EnterAmount
End If

Now if I hit cancel the amount will remain what it was.

But if I use Application.InputBox:
EnterAmount = Application.InputBox("Enter the amount to Hardcode: ", ,
vAmount, , , , , Type:=1)
then if I hit Cancel I will get a False in the cell. How do I make it so
if I hit Cancel with using the Application.Input box the cell will not change
to False but will remain what the cell was when I entered the cell like the
InputBox does.


Thank you for your help,

Steven
 
Dim EnterAmount As Variant

EnterAmount = Application.InputBox(Prompt:="Enter the amount to Hardcode:", _
Type:=1)

If EnterAmount = False Then
'what should happen?
Else
'do the real work
activecell.value = enteramount
end if
 
Dave showed you the code. The explanation is that for InputBox function,
cancel equals "". For InputBox Method, cancel equals "False". So if you use
Application.InputBut you have to change your "If" statement to match whatever
cancel equals.
 

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

Back
Top