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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

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