Consulting

Results 1 to 5 of 5

Thread: find duplicates entries

  1. #1

    find duplicates entries

    Hello,

    I would like to know if it is possible to create a macro that would compare the entries for three columns in a worksheet and then return an error message if there is a duplicate entry.

    For example, I have a worksheet that includes the columns "parcel number", "book", "page" and "instrument number". I would like to know if there are duplicate entries of "parcel number & book & page" or "parcel number & instrument number". I can have duplicate entries of each of the fields individually but I do not want duplicate entries of the combination of the fields.

    Thanks

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Give this tool a try. If you need more, let us know.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    or here is some code i tried, it seemed to work
    [VBA]Sub test_MatchCells()
    Dim i As Long, cell As Range, rng1 As Range, rng2 As Range

    Set rng1 = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
    Set rng2 = Range(Range("D1"), Range("D" & Rows.Count).End(xlUp))
    On Error Resume Next
    For Each cell In rng1
    i = WorksheetFunction.Match(cell.Value, rng2, 0)
    If Err Then
    Err.Clear
    Else
    MsgBox "Found " & cell.Value & " In parcel No and " & cell & " in instrument No @ " & "Row:" & i
    End If
    Next

    End Sub
    [/VBA]
    if its code your after

  4. #4
    It will be several thousand rows. The table is linked to an access database and each row is a record in access. My columns are as follows:
    Number of records, TaxAcct, MVPParcelNumber, Document Type, Book number, Page, Instrument Number, Date Recorded and Comments.
    The number of records, TaxAcct, and MVPParcelNumber will have information in them but the other columns may not.





  5. #5
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Conditional formatting is definately the way to go! its quick and efficient, so, highlight your entire range, then in the white box below the word FILE on the toolbar(currently showing A1) type the range name Range1, then choose FORMAT, CONDITIONAL FORMATTING, change from Cell Is to Formula Is and then enter this =IF(countif(Range1, A1)>1,TRUE,FALSE) select your format colour and your done!, all duplicates will now show up!, i believe this to be better than code as its a worksheet function and instantaneous.
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

Posting Permissions

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