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. #6
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Move the code into workbook module. Like

    Code:
    Option Explicit
    
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
        Dim rFound As Excel.Range
        Dim rCount  As Long
        
        Select Case UCase$(Sh.Name)
            Case "USED CONTRACTS", "ARCHIVE"    '<<<<< add more sheets
                If Target.Column = 2 Then
                    
                    rCount = Application.WorksheetFunction.CountIf(Sh.UsedRange.Columns(2), Target.Value)
                    
                    If rCount > 1 Then
                        Set rFound = Sh.Range("B:B").Find(What:=Target.Value, MatchCase:=False, Lookat:=xlWhole)
                         
                        If Not rFound Is Nothing Then
                            
                            If MsgBox("The registration Number  " & Target.Value & _
                            "    has been found in row  " & rFound.Row & 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, True
                                rFound.Activate
                            End If
                        End If
                    End If
                End If
         End Select
    
    End Sub
    Edit: Code edited.
    Last edited by Admin; 07-25-2013 at 03:00 PM.
    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
  •