Results 1 to 27 of 27

Finding duplicates in a column, prompt user then delete the current one

Threaded View

  1. #20
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Finding duplicates in a column, prompt user then delete the current one

    Lifeseeker,
    OK, so you manually input data into both sheets and they are not linked. Got that.

    I don't know what you want deleted, so for the time being this macro deletes the duplicate you just entered (Tell me if you want it another way?). Enter 123 in cell A3 and see if this is what you are after?

    Private Sub Worksheet_Change(ByVal Target As Range)
    
     Dim ws As Worksheet, ws1 As Worksheet
     Dim Mbox As String, cVal As Range, LR1 As Long
     Dim LR As Long, i As Long, found As Range, cel As Range, rng As Range
     Dim cell_to_test As Range
     
         Set ws1 = Sheets("Main")
         LR1 = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row
         
        If Not Intersect(Target, Range("A" & LR1)) Is Nothing Then
              
            Application.ScreenUpdating = 0
            Application.EnableEvents = 0
               Set ws = Sheets("Sub")
               On Error Resume Next
                  LR = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
                  Set rng = ws.Range("A2:A" & LR)
                  
                  Set cVal = ws1.Cells(LR1, 1)
                      For Each cel In rng
                          Set found = rng.Find(what:=cVal, LookIn:=xlValues, LookAt:=xlWhole)
                              If found <> vbNullString Then
                                If Not found Is Nothing Then
                                     Mbox = MsgBox("Duplicate Found, do you want to delete duplicate", vbYesNo, "Duplicate")
                                  If Mbox = vbYes Then
                                   cVal.ClearContents
                                  Else
                                   Resume Next
                                  End If
                                End If
                              End If
                      Next cel
          End If
              Set found = Nothing
            Application.EnableEvents = 1
            Application.ScreenUpdating = 1
    End Sub
    Edit: The system is not allowing me to upload a file, paste this in the worksheet module for "Main".
    Edit* it worked. See file
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

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