Cancel with Input Box
Cancel with Input Box
(OP)
Does anyone know how to handle Cancel with an Input Box, and distinguish it between an empty string when hitting Enter? I've seen code that looks like:
Sub TestInput()
Dim ans As String
ans = InputBox("Response:")
If StrPtr(ans) = 0 Then
MsgBox "You hit cancel"
Exit Sub
ElseIf ans = "" Then
MsgBox "You hit OK with no entry"
Exit Sub
Else
MsgBox "Your answer is " & ans
End If
but when I tried this, and strptr(ans) seems to be a random number? Any ideas what's missing? Using Excel 2002 btw.
Sub TestInput()
Dim ans As String
ans = InputBox("Response:")
If StrPtr(ans) = 0 Then
MsgBox "You hit cancel"
Exit Sub
ElseIf ans = "" Then
MsgBox "You hit OK with no entry"
Exit Sub
Else
MsgBox "Your answer is " & ans
End If
but when I tried this, and strptr(ans) seems to be a random number? Any ideas what's missing? Using Excel 2002 btw.





RE: Cancel with Input Box
I've got Excel 2000.
RE: Cancel with Input Box
RE: Cancel with Input Box
RE: Cancel with Input Box
Just a hunch...
Wheels within wheels / In a spiral array
A pattern so grand / And complex
Time after time / We lose sight of the way
Our causes can't see / Their effects.