Hello,
I am looking into creating a macro that would be prevent the entry of duplicate rows of data, within a worksheet. If the input text exists, there should be a warning message, with no option to leave the duplicated item.
I found the below coding in a different thread. Would it be possible to adjust the below coding to identify duplicate rows of data, from columns A to I? Please let me know if you require more information.
Thanks,
Ken
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Dim mySum As Integer
mySum = 0
If Sh.Name = "Sheet1" Or Sh.Name = "Sheet2" Then ' the names of sheets where col A checked
If Target.Column <> 1 Then Exit Sub
mySum = mySum + Application.CountIf(Sh.Range("A:A"), Target.Value)
If mySum > 1 Then
MsgBox "Invoice Already Exists"
With Application
.EnableEvents = False
.Undo
.EnableEvents = True
End With
End If
ElseIf Sh.Name = "Sheet3" Then ' the name of sheet where col E checked
If Target.Column <> 5 Then Exit Sub
mySum = mySum + Application.CountIf(Sh.Range("E:E"), Target.Value)
If mySum > 1 Then
MsgBox "Invoice Already Exists"
With Application
.EnableEvents = False
.Undo
.EnableEvents = True
End With
End If
End If
End Sub
Bookmarks