Duplicate Check :: Text Box Input to Compare with Excel Sheet Content

Dheepak

Board Regular
Joined
Aug 25, 2013
Messages
64
Hi All,

I created a user-form to enter product ID in textbox1. Product ID is unique. There is list of product ID that is already entered in the sheet1 from A2 to A20. I just want to know how to throw a hard-stop vbcritical error if user tries to enter the product ID in the text box which is already available in the range A2:A20.

Any help would be appreciated.

Thanks in advance.

Regards,
Dheepak
 
The approach I suggest is to not let the user try to add an ID that is already in the data. To do this, disable the button that is used to enter the new user id when the TextBox has such an ID. Here is some code to demonstrate this approach:


  1. Open your “test” Excel file (the one with the data in A2:A20)
  2. Add a form - altF11, Insert, Form
  3. On the form put: A TextBox (TextBox1)and a CommandButton(CommandButton1)
  4. Put the code below in the form’s module
  5. Change “Data” to the name of the sheet holding the data
  6. Save the “test” file
  7. Test a bunch

Code:
Private Sub TextBox1_Change()
    Const DataSheet = [COLOR=#008000][B]“Data”[/B][/COLOR]
    Me.CommandButton1.Enabled = Sheets(DataSheet).Range("A2:A20").Find(Me.TextBox1, LookIn:=xlValues, _
                                        lookat:=xlWhole, MatchCase:=False) Is Nothing
End Sub
Private Sub UserForm_Initialize()
    Me.CommandButton1.Enabled = False
End Sub

This will give you some idea of the approach I suggest. The next step, is to integrate this approach with the code. (Another post)

“It’s easier to stay out than to get out”
 
Upvote 0

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