Hi again.
I would like to prevent duplicate entries to be entered into a spreadsheet when attempting to add with a error message saying "Duplicate Entry".
VBA Script below;
I would like to prevent duplicate entries to be entered into a spreadsheet when attempting to add with a error message saying "Duplicate Entry".
VBA Script below;
Code:
Private Sub ScanTB_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Dim LastRowFilled As Long
Dim DataArray(1 To 4) As String
Dim i As Integer
Dim a As Integer, blnFound As Boolean
Dim strNewName As String
Dim ws As Worksheet
Dim boolFound As Boolean
strNewName = WOTB.Value
For Each ws In Worksheets
If ws.Name Like strNewName Then boolFound = True: Exit For
Next
If boolFound = True Then
Sheets(strNewName).Select
Else
Sheets.Add.Name = strNewName
End If
Cells(1, 5).Select
ActiveCell.Value = "=COUNTA((A:A)-1)"
Cells(1, 1).Select
ActiveCell.Value = "Carton Serial #"
Cells(1, 2).Select
ActiveCell.Value = "PCB Serial #"
Cells(1, 3).Select
ActiveCell.Value = "Employee #"
Columns("A:B").ColumnWidth = 30
Columns("C").ColumnWidth = 11
TextBox1.Font.Size = 28
TextBox1.Value = ActiveSheet.Range("E1").Value + 1
If Me.ScanTB = "" Then
Me.ScanTB.SetFocus
Else
Cells(Rows.Count, 1).End(xlUp).Offset(1).Value = ScanTB.Text
Cells(Rows.Count, 2).End(xlUp).Offset(1).Value = Scan2TB.Text
Cells(Rows.Count, 3).End(xlUp).Offset(1).Value = EMP.Text
Me.Scan2TB = ""
Me.ScanTB = ""
Cancel = True
End If
End Sub
Last edited by a moderator: