User form data validation

jtodd

Board Regular
Joined
Aug 4, 2014
Messages
194
Morning all

As part of a user form I am developing the user has to enter a seal number , but it has to be on the seal list .
The list has 3000 numbers ,
How can I make sure the user only picks a number off the list ?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
What is: "seal list"

Do you mean this is a Listbox?

Well if that is all you have on the UserForm for him to select from he must select some value from the listbox. He will not be able to enter anything.

Please give more details.
 
Upvote 0
You could use a combobox to list all the 'seal' numbers.
 
Upvote 0
I would use a Listbox.

Using a Combobox allows the user to choose a value from the combobox or manually enter a value.
A listbox requires the user to only choose a value in the listbox.
 
Upvote 0
Sorry if I was not clear.
The seal list is just a list of 3000 numbers and the user can only enter a number from this list in the user form.
I need some kind of validation to only allow this - limit to list ?
If I use a list box the list will be huge?
Can I use a combo box and the user type in the value and how would I link the list to the combo box ?

Hope this makes things a bit clearer
 
Upvote 0
So you want to put a number into a combobox and if that number in not one of the 3,000 numbers you want the user to get a message telling him that is not a valid number. Is that what you want?

What is the name of the Combobox?
Where is this list of 3,000 numbers?
 
Upvote 0
With a combobox if the user enters a value that's not on the list then the ListIndex property of the combobox will be -1, something that is easily to check.
Code:
Private Sub Combobox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim idx As Long
    
    idx = ComboBox1.ListIndex

   If idx = -1 Then
       MsgBox "Invalid seal number selected/entered"
       Cancel = True
   End If

End Sub
 
Upvote 0
I did not know that. Thanks for that info.
With a combobox if the user enters a value that's not on the list then the ListIndex property of the combobox will be -1, something that is easily to check.
Code:
Private Sub Combobox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim idx As Long
    
    idx = ComboBox1.ListIndex

   If idx = -1 Then
       MsgBox "Invalid seal number selected/entered"
       Cancel = True
   End If

End Sub
 
Upvote 0
The error message you entered in your script pops up any time I manually enter any value in the combobox. And that value is in the Combobox list.
With a combobox if the user enters a value that's not on the list then the ListIndex property of the combobox will be -1, something that is easily to check.
Code:
Private Sub Combobox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim idx As Long
    
    idx = ComboBox1.ListIndex

   If idx = -1 Then
       MsgBox "Invalid seal number selected/entered"
       Cancel = True
   End If

End Sub
 
Upvote 0
It shouldn't, how did you populate the combobox?

Are you entering the value(s) manually or by selection via the dropdown?
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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