Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check for duplicates in column except target cell 1

Status
Not open for further replies.

Etrigan

Technical User
Feb 3, 2003
3
SE
Hi,

I have a list that is being populated continuously.

I need to compare the target cell (wich will be in column D) with the rest cells in column D and check for duplicates but NOT include the target cell in the search.

With the following code I get the result I want when there is one or more duplicates, but if the value is uniqe it "checks itself".

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

With Worksheets("Partier").Columns("D")
    Set c = .Find(Target.Value, LookIn:=xlValues)
    If Not c Is Nothing Then
        firstaddress = Target.Address
        Do
            MsgBox (c.Offset(columnoffset:=-3).Value & " " & c.Offset(columnoffset:=-1).Value)
            Set c = .FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstaddress
    End If
End With
    
End Sub

I need to exclude the target cell in the search but I'm a newbie when it comes to VBA so I'm stuck, so please help!


Thank's

Glenn
 
I think the following might be what you need (only a minor change to your code):

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
With Worksheets("Partier").Columns("D")
    Set c = .Find(Target.Value, LookIn:=xlValues)
    If Not c Is Nothing Then
        firstaddress = Target.Address
        Do While c.Address <> firstaddress
            If c.Address <> firstaddress Then
            MsgBox (c.Offset(columnoffset:=-3).Value & " " & c.Offset(columnoffset:=-1).Value)
            Set c = .FindNext(c)
            End If
        Loop
    End If
End With
End Sub
 
Thank you so much Fenrirshowl, it works like a charm!

A star is coming your way.

/Glenn
 



Also take a look at Data/Validation in order to PREVENT the wron data from being entered in the first place.

Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top