checking for unique values in user forms in VBA

VBAmalta89

Board Regular
Joined
Mar 25, 2011
Messages
116
i have a user form which contains a text box where the user has to enter a component number. This number is then stored in a worksheet in a particular column (all numbers inputted in the field are stored under each other in column A on worksheet 1)

All the numbers inputted must be unique therefore I need to create a procedure that will check whether the number inputted in the text box already exists in column A on worksheet 1 and prompts if the component number is not unique.

how do u do this?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Perhaps like this

Code:
If IsNumber(Application.Match(Val(textbox1.Value), Sheets("Sheet1").Columns("A"), 0)) Then
'
'it is a duplicate
'
End If
 
Upvote 0
and how do i make the program re enter the number rather than proceeding?

THis is because when the button OK is clicked i want it to prompt the user that the number is not unique and force them to re enter the number.
 
Upvote 0
Do you want the numbers to run in sequence at all?

Or is it totally up to the user to enter it, and it will be accepted as long as it's unique?
 
Upvote 0
i want it to be accepted as long as it is unique in column A of worksheet 1. (the value start in cell A7 and proceed downwards in column A in no particular order)
 
Upvote 0
Try something like

Code:
Do While IsNumber(Application.Match(Val(textbox1.Value), Sheets("Sheet1").Columns("A"), 0))
    MsgBox "Duplicate!", vbExclamation
    textbox1.Value = ""
    textbox1.SetFocus
Loop
 
Upvote 0
@VoG

The code u gave me isnt working. Its giving me an error...what is the IsNumber statement in the code u gave me as thats wer the error seems to be?
 
Upvote 0

Forum statistics

Threads
1,224,608
Messages
6,179,872
Members
452,949
Latest member
Dupuhini

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