Banner

Thursday, July 13, 2017

Textbox Avoid Duplicate Entry Userform Excel VBA



Private Sub TextBox1_AfterUpdate()
Dim a As Long
a = Application.WorksheetFunction.CountIf(Sheet1.Range("A:A"), _
Me.TextBox1.Text)
If a >= 1 Then
Me.TextBox1 = ""
MsgBox "PLease This Name Already submited"
End If
End Sub

Private Sub CommandButton1_Click()
Dim a As Long, x As Long
a = Application.WorksheetFunction.CountIf(Sheet1.Range("A:A"), Me.TextBox1.Text)
x = Application.WorksheetFunction.CountA(Sheet1.Range("A:A")) + 1
If Me.TextBox1 <> "" And Me.TextBox2 <> "" And a = 0 Then
Sheet1.Range("a" & x).Value = Me.TextBox1.Text
Sheet1.Range("B" & x).Value = Me.TextBox2.Text
Else
MsgBox "PLease This Name Already submited Or Textbox Blank"
End If
End Sub

2 comments:

  1. what if i have 1 column same column multiple sheets what can i do ?

    ReplyDelete
  2. I want to check 3 or more criteria to check either record has already entered or not, plz guide

    ReplyDelete

Please do not enter any spam message in comment box