View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Input Box - CANCEL

If it there are different meanings to an empty string returned by the user
clicking OK and an empty string returned by the user clicking Cancel, use
code like the following:

Dim Res As String
Res = InputBox("What is the number?")
If StrPtr(Res) = 0 Then
MsgBox "User Clicked Cancel"
ElseIf Res = vbNullString Then
MsgBox "User Clicked OK with no input"
Else
MsgBox "User Entered " & Res
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"Corey" wrote in message
...
Sub InputNumber()
res = InputBox("What is the number?")
If res = "" Then
Exit Sub
End If
End Sub


"Danny" wrote in message
...
Hi,

Please edit the macro below so when the user clicks on CANCEL or CLOSE
the
box, Range A1 existing input won't change.

Sub InputNumber()
Range("A1").Value = InputBox("What is the number?")
End Sub

Thank you.