pugap
Mechanical
- Nov 18, 2003
- 45
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.