Duplicate Entries

DanSMT

Board Regular
Joined
Sep 13, 2019
Messages
203
Office Version
  1. 2013
Platform
  1. Windows
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;

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:

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

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