+ Reply to Thread
Results 1 to 9 of 9

Pop up message box if duplicate exist

Hybrid View

  1. #1
    Forum Contributor HerryMarkowitz's Avatar
    Join Date
    09-10-2012
    Location
    Europe
    MS-Off Ver
    Office 2021 - Win10
    Posts
    1,014

    Pop up message box if duplicate exist

    Hi,
    How can I pop up message box if duplicate exist in A column ?
    I found following code but it is not working.
    Please correct following code.
    Thanks in advance.
    Private Sub Worksheet_Change(ByVal Target As Range) 
        Dim Found As Range 
        If Target.Column <> 1 Then Exit Sub 
         
        Set Found = Range("A1", Cells(Rows.Count, 1).End(xlUp)).Find _ 
        (Target.Value, LookIn:=xlValues, lookat:=xlWhole) 
        If Not Found Is Nothing Then 
            If Target.Address = Found.Address Then Exit Sub 
            MsgBox "Ther is a duplicate entry at row " & Found.Row & "." 
            Target = "" 
        End If 
    End Sub
    Sub DontForgetThese()
         If Your thread includes any code Then Please use code tags...
         If Your thread has been solved Then Please mark as solved...
         If Anybody has helped to you Then Please add reputation...
    End Sub

  2. #2
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    330

    Re: Pop up message box if duplicate exist

    Set Found = Range("A1", Cells(Rows.Count, 1).End(xlUp)).Find _ 
        (Target.Value, After:=Target.address, LookIn:=xlValues, lookat:=xlWhole)
    Sub Reputation()
    Dim Problem as Variant
    Dim Reputation as Integer
    For Each Problem in Forum.Threads
        If Problem.Title = "*[Solved]*" and Solver.Name = "Leon V (AW)" Then Reputation = Reputation + 1
    Next Problem
    End Sub

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Pop up message box if duplicate exist

    Try this
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim x As Long
        If (Target.Column <> 1) + (Target.Count > 1) Then Exit Sub
            If Target.Value <> "" Then
            x = WorksheetFunction.CountIf(Columns(1), Target.Value)
            If x > 1 Then
                MsgBox Target.Value & " is already taken"
                With Application
                    .EnableEvents = False
                    .Undo
                    .EnableEvents = True
                End With
            End If
        End If
    End Sub

  4. #4
    Forum Contributor HerryMarkowitz's Avatar
    Join Date
    09-10-2012
    Location
    Europe
    MS-Off Ver
    Office 2021 - Win10
    Posts
    1,014

    Re: Pop up message box if duplicate exist

    Hi Leon V (AW),
    I dont understand your answer.
    Is it possible adding an excel file ?
    Thank you.

  5. #5
    Forum Contributor HerryMarkowitz's Avatar
    Join Date
    09-10-2012
    Location
    Europe
    MS-Off Ver
    Office 2021 - Win10
    Posts
    1,014

    Re: Pop up message box if duplicate exist

    Hi jindon,
    I dont understand your answer.
    Is it possible adding an excel file ?
    Thank you.

    Note: I dont want Private Sub Worksheet_Change(ByVal Target As Range) issue.
    I want regular procedure...

  6. #6
    Forum Contributor HerryMarkowitz's Avatar
    Join Date
    09-10-2012
    Location
    Europe
    MS-Off Ver
    Office 2021 - Win10
    Posts
    1,014

    Re: Pop up message box if duplicate exist

    I found following link regarding this issue.
    Solution in following link is using conditional highlighting to show duplicates.
    But I want to show duplicates in msgbox !
    Any idea ?
    http://www.excelforum.com/excel-prog...-column-a.html

  7. #7
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    330

    Re: Pop up message box if duplicate exist

    Private Sub Worksheet_Change(ByVal Target As Range) 
        Dim Found As Range 
        If Target.Column <> 1 Then Exit Sub 
         
        Set Found = Range("A1", Cells(Rows.Count, 1).End(xlUp)).Find _ 
        (Target.Value, After:=Target.address, LookIn:=xlValues, lookat:=xlWhole)
        If Not Found Is Nothing Then 
            If Target.Address = Found.Address Then Exit Sub 
            MsgBox "Ther is a duplicate entry at row " & Found.Row & "." 
            Target = "" 
        End If 
    End Sub

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Pop up message box if duplicate exist

    You could put Excel's vValidation on all the cells of column A with the formula
    =(COUNTIF(A:A, A1)=1)
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  9. #9
    Forum Contributor HerryMarkowitz's Avatar
    Join Date
    09-10-2012
    Location
    Europe
    MS-Off Ver
    Office 2021 - Win10
    Posts
    1,014

    Re: Pop up message box if duplicate exist


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 7
    Last Post: 07-12-2012, 10:30 AM
  2. Replies: 6
    Last Post: 04-09-2012, 02:26 PM
  3. Replies: 1
    Last Post: 01-29-2012, 01:19 PM
  4. Data may exist in the sheet(s) message
    By cedtech23 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-21-2006, 10:15 AM
  5. [SOLVED] Checking that file exist and if not display a message
    By jab@consignit.se in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-16-2006, 10:20 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1