Accepting unique values in user form

VBAmalta89

Board Regular
Joined
Mar 25, 2011
Messages
116
I have a user form where the user is asked to input a component number into a text box. these numbers are then stored in column A in worksheet 1.

I require each of these component numbers entered to be unique. So far i have managed to achieve something close to this by using the following code:

Do While IsNumeric(Application.Match(Val(compnum.Value), Sheets("Component Information").Columns("A"), 0))
MsgBox "The component number entered is not unique!", vbExclamation
compnum.Value = ""
compnum.SetFocus
Loop

however, the problem is that while it does prompt me that the number isnt unique, it still accepts all the other data inputted and inputs it into the worksheet with a blank component number.

What i want is that it doesnt allow the user to proceed when pressing Ok in the user form until the component number entered is unique.

Any ideas how i can solve this problem?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi,

something along these lines.
It's untested so there may be errors.

Code:
ValidEntry = False
 
Do 
 
If IsNumeric(Application.Match(Val(compnum.Value), Sheets ("Component Information").Columns("A"), 0))
 
ValidEntry = True
 
End If
 
Else
MsgBox "The component number entered is not unique!", vbExclamation
compnum.Value = ""
compnum.SetFocus
End If
 
 Loop Until ValidEntry
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,267
Members
452,902
Latest member
Knuddeluff

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