+ Reply to Thread
Results 1 to 10 of 10

Very Difficult & Detailed Macro to find Duplicates

Hybrid View

erock24 Very Difficult & Detailed... 02-22-2007, 06:30 PM
mudraker it can be done it would... 02-22-2007, 07:50 PM
erock24 In this example there are... 02-23-2007, 11:56 AM
erock24 Sorry i dont't the file... 02-23-2007, 12:01 PM
erock24 here is the same example, but... 02-23-2007, 12:24 PM
  1. #1
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299

    Very Difficult & Detailed Macro to find Duplicates

    I work with large spreadsheets. I was hoping that someone would know how to create a macro that will take selected cells in column C and search all of column C for exact duplicate entries. The macro envisioned would let you select cells to test. If a dulicate entry is found I would need the macro to test the cells in column E against one another. If both C & E match exact (if possible maybe display the findings in a pop up box) I would like the macro to ask me if I want to delete the duplicate entry, if yes, delete the entire row. If no, skip it and move to the next one. If C but not E match I would need the macro to ask me if I want to remove thetest cell. if yes, cut out the entire row of the TEST cell and paste it in a new sheet. If no skip it and move on.
    Am I just dreaming or can this be done. If it can be done, but more info is needed let me know.
    I thank you very much for your time and help and effort.

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    it can be done

    it would make it easier if you could paste an example of your workbook

  3. #3
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299
    In this example there are some duplicates for C only and some for both C&E. I would be without words if a macro could be built as described in my 1st post.

  4. #4
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299
    Sorry i dont't the file attached the 1st time, this should work.
    Also, remember, I need C to be an exact match. and if that is true then test E and so on.

    Thank you very much for your help.

    If you need another example or additional info let me know.
    Attached Files Attached Files
    Last edited by erock24; 02-23-2007 at 12:04 PM.

  5. #5
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299
    here is the same example, but more detailed to what I need.
    Also, in the example when I say delete I mean the whole row same goes for cut and paste.

    thank you
    Attached Files Attached Files
    Last edited by erock24; 02-23-2007 at 12:26 PM.

  6. #6
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Try this macro
    I beleive it does everyting you asked for

    Sub FindDuplicates()
       Dim Rng As Range
       Dim rFound As Range
       Dim rFrom
       
       Dim sFind As String
       Dim sMB As String
       Dim wS As Worksheet
       
       Set wS = ActiveSheet
       For Each Rng In Selection
          If Rng.Column = 3 Then
             Set rFrom = Rng
             Do
                Set rFound = wS.Columns("c").Find(What:=Rng.Value, _
                   After:=rFrom, LookIn:=xlFormulas, _
                   LookAt:=xlWhole, SearchOrder:=xlByRows, _
                   SearchDirection:=xlNext, _
                   MatchCase:=False, SearchFormat:=False)
             
                If Not rFound Is Nothing Then
                   If rFound.Row = Rng.Row Then
                      Exit Do
                   End If
                   If rFound.Address <> Rng.Address Then
                      If rFound.Offset(0, 2).Value = Rng.Offset(0, 2).Value Then
                         sMB = MsgBox("Duplicates Found Rows " & rFound.Row & " & " & Rng.Row _
                            & Chr(10) & Chr(10) _
                            & "Delete Duplicate from Row " & rFound.Row, _
                            vbYesNo + vbQuestion)
                         If sMB = vbYes Then
                            wS.Rows(rFound.Row).Delete
                            Set rFrom = Rng
                         Else
                            Set rFrom = rFound
                         End If
                      Else
                         sMB = MsgBox("Duplicates Found Rows " & rFound.Row & " & " & Rng.Row _
                            & Chr(10) _
                            & "With Non Matching Column E Entries" _
                            & Chr(10) _
                            & "Remove Row " & rFound.Row & " Entry", _
                            vbYesNo + vbQuestion)
                         If sMB = vbYes Then
                            Sheets.Add
                            wS.Rows(rFound.Row).Copy
                            ActiveSheet.Paste
                            wS.Rows(rFound.Row).Delete
                            Set rFrom = Rng
                         Else
                            Set rFrom = rFound
                         End If
                      End If
                   End If
                End If
             Loop
          End If
       Next Rng
       CreateObject("WScript.Shell").Popup "Process Finished", 2, _
          "This Message Self Destructs in 2 seconds "
    End Sub

+ Reply to Thread

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