View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_2110_] Rick Rothstein \(MVP - VB\)[_2110_] is offline
external usenet poster
 
Posts: 1
Default Cleaning up code

This is probably how I would have written it...

Sub xxCodes()
Dim InpType As String
Dim shtInput As String
Do
InpType = InputBox("Enter the school code")
If InpType Like "[xX][xX][1-5]" Then
shtInput.Range("State_Code") = UCase(InpType)
shtInput.Range("product") = ""
Exit Do
End If
Loop While vbYes = MsgBox("Incorrect school code do you " & _
"want to try again?", vbYesNo)
End Sub

I do have one question though... your are referencing a worksheet variable
shtInput, but I don't see where you have set it at... are you doing it
through some kind of global setting or did you just forget to include it in
your code?

Rick

"Brad" wrote in message
...
I think this is better - suggestions are welcome

Sub xxlCodes1()
Dim InpType As String
Dim tryagain As Long
tryagain = 6
Do Until tryagain = 7
InpType = UCase(InputBox("Enter the school code"))
Select Case InpType
Case "xx1" To "xx5"
shtInput.Range("State_Code") = InpType
shtInput.Range("product") = ""
tryagain = 7
Case Else
tryagain = MsgBox("Incorrect school code do you want to try
again?", vbYesNo)
End Select
Loop
End Sub



"Brad" wrote:

The following code works but I think could be improved.

Any suggestions would be appreciated!

Sub xxCodes()
Dim InpType As String
Dim tryagain As Long
startinput:
InpType = UCase(InputBox("Enter the school code"))
Select Case InpType
Case "XX1" To "XX5"
shtInput.Range("State_Code") = InpType
shtInput.Range("product") = ""
Case Else
tryagain = MsgBox("Do you want to try again", vbYesNo)
If tryagain = 6 Then
GoTo startinput
Else
End
End If
End Select
End Sub