View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
papou[_2_] papou[_2_] is offline
external usenet poster
 
Posts: 112
Default Macro for checking duplicate entries

Hello Ken
Right click on the worksheet tab, select view code and paste the code below.

HTH
Cordially
Pascal

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column < 5 Or Target.Cells.Count 1 Then Exit Sub
r = Target.Row
On Error Resume Next
If Application.CountA(Range(Cells(1, 5), Cells(Target.Row - 1, 5)),
Target.Value) < 0 Then
On Error GoTo 0
On Error Resume Next
If MsgBox("This value has been found in row " & _
Application.Match(Target.Value, Range(Cells(1, 5), Cells(Target.Row - 1,
5)), 0) _
& vbLf & "do you wish to continue?", vbQuestion + vbYesNo, "ID found") =
vbYes Then
On Error GoTo 0
Exit Sub
Else
Application.EnableEvents = False
Target.ClearContents
Application.EnableEvents = True
End If
End If
End Sub

"Ken" a écrit dans le message de news:
...
Hey, Group!
Another post by a macro noob (trying hard to learn something)....I
have a spreadsheet that has a column for entering a unique ID number
(6 digits) Column E, and I need to know that I have entered a
previously entered ID, with a warning, and "Do you wish to
continue?"....with the warning telling me the line # of the previously
entered ID....as I have it right now I have a just a formula that will
flag the new cell and turn it a different color, with no reference to
the previously entered ID, which is ok, but lacking....I really need a
macro, and I have no idea where to start, although I can maneuver
around the VBA somewhat....I'm really struggling on this one...does
anyone have something similar that I might be able to use? Any help
will be greatly appreciated.
Thanks in advance!!!
Ken