View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Case Sensitive Input Box

There is a small problem with the code I posted... I changed a variable name
at the last moment and did not correct all the occurrences of that variable,
so the code won't work as posted. In addition, I performed an unneeded
correction on that variable (wouldn't affect the functionality of the code,
only its efficiency). Here is the corrected code...

Sub Test()
Dim InputBoxText As String
Const Months As String = "*January*February*Marcy*April*May*June*July" & _
"*August*September*October*November*December"
'
' Assign user input to the InputBoxText variable here
'
If Len(InputBoxText) 2 And InStr(1, Months, "*" & _
InputBoxText, vbTextCompare) 0 Then
MsgBox "The input was a valid month!"
Else
MsgBox "That is not a month name I ever saw."
End If
End Sub

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
It's hard to say how to fit this code into your existing code without
seeing it or knowing what you want to do when a bad month name is input;
however, you should be able to modify the following code to suit your
purposes...

Sub Test()
Dim InputBoxText As String
Const Mnths As String = "*January*February*Marcy*April*May*June*July" & _
"*August*September*October*November*December"
'
' Assign user input to the InputBoxText variable here
'
If Len(InputBoxText) 2 And InStr(1, Mnths, "*" & _
Replace(Ans, "*", ""), vbTextCompare) 0 Then
MsgBox "The input was a valid month!"
Else
MsgBox "That is not a month name I ever saw."
End If
End Sub

The above code will test the user's input to see if it is at least 3
characters long and also test to see if those characters actually make up
the beginning text of any month name.

--
Rick (MVP - Excel)


"Keep It Simple Stupid"
wrote in message
...
I have an input box for the user to enter the full name of the month for
the
report. Then there is a whole slew of code that follows. The value is
then
entered into the sheet, and I have formulas that look for this value.

Unfortunately, if the user does not enter the entire name of the month
and
in all caps, it doesn't work.

How can I make it so I have some kind of error-checker. For example, if
the
users enters january, January, or JANYOUARIE then the code will stop, but
if
the user enters JANUARY, FEBRUARY, MARCH, ... etc, then the code
continues.
I cant figure out the if/then/else