Results 1 to 6 of 6

Preventing duplicate row entries

Threaded View

  1. #1
    Registered User
    Join Date
    10-21-2009
    Location
    Vancouver, Canada
    MS-Off Ver
    Excel 2003
    Posts
    5

    Preventing duplicate row entries

    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
    Last edited by Leith Ross; 10-21-2009 at 09:02 PM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1