Fix InputBox - Returning Empty String

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If the user clicks OK or presses Enter, the InputBox function should return whatever is in the text box, but when I click either OK or press Enter is returns a zero-lenght string (""). How do I fix this problem?
 
You are apparently not aware of how to see what is returned. See answer to
original posting of this question for an example.

--
Regards,
Tom Ogilvy

Gary Dygert said:
If the user clicks OK or presses Enter, the InputBox function should
return whatever is in the text box, but when I click either OK or press
Enter is returns a zero-lenght string (""). How do I fix this problem?
 
paste you code - we will not be able to tell you exactly if you don't!

Tip, put Option Explicit at the very top of all code pages - you might have a misspelled variable!
If you prefer to avoid Option Explicit then you are asking for this kind of problem!

Gary Dygert said:
If the user clicks OK or presses Enter, the InputBox function should return whatever is in the text box, but when I
click either OK or press Enter is returns a zero-lenght string (""). How do I fix this problem?
 
Sub InformationReferral()
'
' InformationReferral Macro
' Macro recorded 3/24/2004 by MCIL
'
' Keyboard Shortcut: Ctrl+Shift+Z
'
Workbooks.Open Filename:= _
"C:\My Documents\Excel\Referral Input Form 1 (version 1).xls"
Range("A1").Select
Range("C8:I8").Select
mydate = InputBox("ENTER THE DATE IN (MM - DD - YY) FORMAT")
MsgBox "Continue the macro"
Range("N8:T8").Select
MyName = InputBox("MY NAME")
MsgBox "Continue the macro"
and so on and on
 
Not entirely sure what you hope to achieve here???
You select ranges but but do nothing with them!
You get input user but do nothing with it! (you dont even check to see if they cancelled!)

Some examples of use for InputBox...

If you want the InputBox text the user entered into a cell - do this...
Dim sInput As String
sInput = InputBox("ENTER THE DATE IN (MM - DD - YY) FORMAT")
If sInput = "" Then Exit Sub 'user cancelled - exit this sub
Sheet1.Range("A1").Value = sInput


If you want the InputBox to have a default value from your sheet - do this...
Dim sInput As String
sInput = InputBox("ENTER THE DATE IN (MM - DD - YY) FORMAT", "", Sheet1.Range("A1").Value)
If sInput = "" Then Exit Sub 'user cancelled - exit this sub
Sheet1.Range("A1").Value = sInput


Workbooks.Open Filename:= _
"C:\My Documents\Excel\Referral Input Form 1 (version 1).xls"
Range("A1").Select
Range("C8:I8").Select
mydate = InputBox("ENTER THE DATE IN (MM - DD - YY) FORMAT")
MsgBox "Continue the macro"
Range("N8:T8").Select
MyName = InputBox("MY NAME")
MsgBox "Continue the macro"
and so on and on
 

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