Thread: Cancel InputBox
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Alfredo_CPA Alfredo_CPA is offline
external usenet poster
 
Posts: 45
Default Cancel InputBox


Per,

When I hit cancel the code runs wrong. Here is the whole code:


Sub IfIserrorNew()
If IsEmpty(ActiveCell) Then
MsgBox " You Are In an Empty Cell ! Please select the cell with
the error value", 16, "My Friend"
Else
MyAns = MsgBox("Do you want to replace formula with ISERROR?",
vbYesNo + vbQuestion, "HIDE ERRORS??")
If MyAns = vbNo Then Exit Sub
myerrorvalue = Application.InputBox("Enter the value you want to
see instead of the error." , "Pick Option", Type:=2)
MyOriginalFormula = ActiveCell.Formula
MyOriginalFormula = Right(MyOriginalFormula,
Len(MyOriginalFormula) - 1)
If myerrorvalue = "" Then
MsgBox "Nothing entered, or Cancel"
ElseIf IsNumeric(myerrorvalue) Then
ActiveCell.Formula = "=IF(ISERROR(" & MyOriginalFormula
& ")," & myerrorvalue & ",(" & MyOriginalFormula & "))"
Else
ActiveCell.Formula = "=IF(ISERROR(" & MyOriginalFormula &
"),""" & myerrorvalue & """,(" & MyOriginalFormula & "))"
End If
End If

"Per Jessen" wrote:

Hi

Look at this:

Sub aaa()
a = InputBox("Enter a value or text")
If a = "" Then MsgBox ("No entry, or Cancel")
If IsNumeric(a) Then
msg = MsgBox("Number")
Else
MsgBox ("Text")
End If
End Sub

Regards,
Per

"Alfredo_CPA" .(donotspam) skrev i meddelelsen
...
Hi,

Does anybody knows how to instruct VBA to diferentiate between a Cancel in
the InputBox and a cero entered in the impiut box? (excel 2003)
I have this code:
ElseIf myerrorvalue = False Then Exit Sub '(errorvalue is the result of
the
inputbox)

VBA is taking a 0 (cero) value as False (just like if the user click the
cancel button) and exits the sub, but I need the code to keep going

Thanks