Results 1 to 10 of 21

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

Hybrid View

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

    Try this code.

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
         
        Dim rFound As Excel.Range
        Dim rCount  As Long
        
        
        If Target.Column = 2 Then
            
            rCount = Application.WorksheetFunction.CountIf(Me.UsedRange.Columns(2), Target.Value)
            
            If rCount > 1 Then
                Set rFound = 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 Sub
    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)

  2. #2
    Member
    Join Date
    May 2013
    Posts
    84
    Rep Power
    13
    Hi

    How can i amend the code so that it would also check in two other sheets one called used contracts and one called archive and take you there
    if possible

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
  •