Error Checking Input Box

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am working with this code for an inputbox. But I'm not sure how to trap user entry outside of the allowable values of 1-7. With an invalid error, keep prompting the user to enter a value until an allowable one is selected, or they hit CANCEL.

Code:
ui1 = InputBox("Select: " & Chr(13) & _
            "(1)   Diamonds" & Chr(13) & _
            "(2)   Fields" & Chr(13) & _
            "(3)   Courts" & Chr(13) & _
            "(4)   Trails" & Chr(13) & _
            "(5)   Passive" & Chr(13) & _
            "(6)   ALL", "Setup Sheet Compilation", "6")
        If ui1 = "" Then
            Exit Sub
        ElseIf ui1 = "1" Then
            pop_Dsvc svcnum
        ElseIf ui1 = "2" Then
            pop_Fsvc svcnum
        ElseIf ui1 = "3" Then
            pop_Csvc svcnum
        ElseIf ui1 = "4" Then
            pop_Tsvc svcnum
        ElseIf ui1 = "5" Then
            pop_Psvc svcnum
        ElseIf ui1 = "6" Then
            pop_Dsvc svcnum
            pop_Fsvc svcnum
            pop_Csvc svcnum
            pop_Tsvc svcnum
            pop_Psvc svcnum
        Else
            MsgBox "Error"
        End If
    End If

I tried a "Do/Loop Until", but I ran into a snag when checking the value entered. Since the allowable values are entered as text, I couldn't figure out how to isolate a text value of 1 to 7 from just a random string.

Code:
     Do        
        ui1 = InputBox("Select: " & Chr(13) & _
            "(1)   Diamonds" & Chr(13) & _
            "(2)   Fields" & Chr(13) & _
            "(3)   Courts" & Chr(13) & _
            "(4)   Trails" & Chr(13) & _
            "(5)   Passive" & Chr(13) & _
            "(6)   ALL", "Setup Sheet Compilation", "6")
     Loop Until cDbl(ui1) > 0 and cDbl(ui1) < 7
        If ui1 = "" Then
            Exit Sub
        ElseIf ui1 = "1" Then
            pop_Dsvc svcnum
        ElseIf ui1 = "2" Then
            pop_Fsvc svcnum
        ElseIf ui1 = "3" Then
            pop_Csvc svcnum
        ElseIf ui1 = "4" Then
            pop_Tsvc svcnum
        ElseIf ui1 = "5" Then
            pop_Psvc svcnum
        ElseIf ui1 = "6" Then
            pop_Dsvc svcnum
            pop_Fsvc svcnum
            pop_Csvc svcnum
            pop_Tsvc svcnum
            pop_Psvc svcnum
        Else
            MsgBox "Error"
        End If
    End If

Suggestions?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Use a combobox instead with Style = DropDownList and populate it with 1,2,3,4,5,6,7. Then you don't have to do any error checking at all.
 
Upvote 0
Solution
Yeah Jeff, that works to!
Thanks for the suggestion.
 
Upvote 0

Forum statistics

Threads
1,215,113
Messages
6,123,165
Members
449,099
Latest member
bes000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top