Consulting

Results 1 to 3 of 3

Thread: Solved: Alter exsisting code to find duplicate entries

  1. #1
    VBAX Contributor
    Joined
    Dec 2006
    Posts
    193
    Location

    Solved: Alter exsisting code to find duplicate entries

    I wish to alter the code below (Which Was Posted in This Form ) to check for duplicate entries being pasted in collums " A,B,C" .I have tried altertering it my self but keep getting it wrong

    [VBA]
    Private Sub Worksheet_Change(ByVal Target As Range)
    Const WS_RANGE As String = "B:AA" '<== change to suit
    Dim mpFormula As String

    On Error GoTo ws_exit
    Application.EnableEvents = False

    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    With Target
    If .Column Mod 5 = 2 Then
    mpFormula = "=SUMPRODUCT((MOD(COLUMN(B2:AA200),5)=2)*" & _
    "(B2:AA200<>"""")*(B2:AA200=" & .Address & "))"
    If Me.Evaluate(mpFormula) > 1 Then
    MsgBox "duplicate"
    End If
    End If
    End With
    End If

    ws_exit:
    Application.EnableEvents = True
    End Sub
    [/VBA]

    Thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Duplicates per column or overall.

    This is per column

    [vba]

    Private Sub Worksheet_Change(ByVal Target As Range)
    Const WS_RANGE As String = "A:C" '<== change to suit

    On Error GoTo ws_exit
    Application.EnableEvents = False

    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    With Target
    If Application.CountIf(Target.EntireColumn, Target.Value) > 1 Then
    MsgBox "duplicate"
    End If
    End With
    End If

    ws_exit:
    Application.EnableEvents = True
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Contributor
    Joined
    Dec 2006
    Posts
    193
    Location
    THANK YOU

Posting Permissions

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