Getting 0 to not equal False

  • Thread starter Thread starter mkerstei
  • Start date Start date
M

mkerstei

Hi,
I have a macro that is supposed to prompt for some data. If the use
hits cancel, I would like the macro to end. However, if the use
inputs 0 (the default), I need the macro to continue running.
Unfortunately, right now the macro is ending if you hit cancel, o
input 0 and hit OK. Any suggestions would be much appreciated.
Thanks.

My code:
Dim Depreciation
Depreciation = Application.InputBox(prompt:="Depreciation?"
Default:=Range("p5"), Type:=1)
If Depreciation = False Then
End
Else
Range("P5").Select
ActiveCell.FormulaR1C1 = _
Depreciation
End I
 
On the line

If Depreciation = False Then

put False in double quotes:

If Depreciation = "False" Then

Hope this helps,

Hutch
 
I think you're mistaken.

I bet that the user hit entering the 0, but hitting the cancel button.

And I think I'd change that "End" statement to "exit sub"

End statements can cause trouble that may be difficult to debug later.
 
Hmm...I put quotations around 'False' as well as replaced 'End' with
'Exit Sub'.
Unfortunately, the problem persists. If I type any number besides 0
and hit enter, the macro will continue, but entering '0' will end the
sub. Any other suggestions?
 
Yeah, I totally put the quotes in a lower part of the macro, so
obviously the macro never had a chance to test the "False". It worked,
and it was so simple I'm embarassed. Thank you very much Hutch!
 

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