LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
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




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cleaning up some code? Patrick[_14_] Excel Programming 3 August 16th 06 12:02 AM
Help Cleaning up Code Lost and Looking for Help Excel Programming 1 May 24th 06 02:26 PM
Need help Cleaning up Code Joel Mills Excel Programming 5 December 16th 04 10:36 PM
Help with shortening/cleaning some code please roy Excel Programming 3 June 3rd 04 11:49 PM
VBA Code -- Cleaning Data Craig[_8_] Excel Programming 2 December 12th 03 12:21 AM


All times are GMT +1. The time now is 06:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"