Validate userform textbox entry with Sheet range.

J

Jock

Users can input numeric values into Textbox 1 on userform1.
Upon exit from the textbox, how do I check Sheet1, column D for the same
value (ie a duplicate)?
tia
 
J

Jacob Skaria

Something like the below..

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If WorksheetFunction.CountIf(Sheets("Sheet1").Range("D:D"), _
TextBox1.Text) > 0 Then
TextBox1.Text = "": MsgBox "Already Exists": Cancel = True
End If
End Sub

If this post helps click Yes
 
M

muddan madhu

Private Sub TextBox1_Change()
Set lookv = Sheets("sheet1").Range("D:D")
text1 = Trim(UserForm1.TextBox1.Value)
With Application.WorksheetFunction
If .CountIf(lookv, text1) > 1 And text1 <> "" Then MsgBox "dup entry"
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top