Results 1 to 10 of 21

Thread: VBA To Display Pop Up Alert When Duplicate Entry Is Made

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #20
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Is this what you are after ?

    Code:
    Option Explicit
    
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
        Dim rFound  As Excel.Range
        Dim rCount  As Long
        Dim Shts    As Variant
        Dim i       As Long
        
        Shts = Array("CONTRACTS", "USED CONTRACTS", "ARCHIVE")
        
        Select Case UCase$(Sh.Name)
            Case "CONTRACTS", "USED CONTRACTS", "ARCHIVE"   '<<<<< add more sheets (in upper case)
                If Target.Column = 2 Then
                    For i = LBound(Shts) To UBound(Shts)
                        rCount = rCount + Application.WorksheetFunction.CountIf(Worksheets(Shts(i)).UsedRange.Columns(2), Target.Value)
                        If rCount And rFound Is Nothing Then
                            Set rFound = Worksheets(Shts(i)).UsedRange.Columns(2).Find(What:=Target.Value, MatchCase:=False, Lookat:=xlWhole)
                        End If
                        If rCount > 1 Then
                            If MsgBox("The registration Number  " & Target.Value & _
                                    "    has been found in row  " & rFound.Row & vbLf & "on Sheet '" & rFound.Parent.Name & "'" & vbCrLf & vbCrLf & _
                                    "Do you want to view this entry?", vbQuestion + vbYesNo, "Confirm") = vbYes Then
                                 
                                 '// You might want to delete the 'new' entry/entire line here
                                 '// otherwise the suplicate remains.
                                 '// Application.EnableEvents = False
                                 '// Target.Value = vbNullString
                                 '// Application.EnableEvents = True
                                 
                                Application.Goto rFound
                                'rFound.Activate
                                Exit For
                            End If
                        End If
                    Next
                End If
         End Select
    
    End Sub
    Last edited by Admin; 07-26-2013 at 10:11 AM.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

Similar Threads

  1. Code to pop up message when there is a variance
    By Howardc in forum Excel Help
    Replies: 1
    Last Post: 08-13-2013, 12:45 PM
  2. Replies: 6
    Last Post: 05-16-2013, 09:56 AM
  3. Replies: 7
    Last Post: 04-22-2013, 01:41 PM
  4. Save Workbook For Each Change Made In A Range
    By Stalker in forum Excel Help
    Replies: 4
    Last Post: 03-22-2013, 08:54 PM
  5. Macro for Contra entry
    By ravichandavar in forum Excel Help
    Replies: 2
    Last Post: 08-12-2012, 09:47 PM

Posting Permissions

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