1. #1
    Justin7
    Justin7's Avatar Become A Pro!
    Join Date: 07-31-06
    Posts: 8,577
    Betpoints: 1506

    Excel error checking

    I have a list of 20 names in cells A1 through A20. I want to be sure no names are repeated -- if a name occurs twice in the list, that player is being weighted double which is a problem.

    Is there an easy macro to see if any of the names in that range are identical (to give an error message)?

  2. #2
    MonkeyF0cker
    Update your status
    MonkeyF0cker's Avatar Become A Pro!
    Join Date: 06-12-07
    Posts: 12,144
    Betpoints: 1127

    Are you sure the names will be identical?

  3. #3
    Justin7
    Justin7's Avatar Become A Pro!
    Join Date: 07-31-06
    Posts: 8,577
    Betpoints: 1506

    Quote Originally Posted by MonkeyF0cker View Post
    Are you sure the names will be identical?
    Yes.

  4. #4
    MonkeyF0cker
    Update your status
    MonkeyF0cker's Avatar Become A Pro!
    Join Date: 06-12-07
    Posts: 12,144
    Betpoints: 1127

    Code:
        Dim names(0 To 19) As String
        For i = 0 To 19
            names(i) = Range("A1").Offset(i, 0)
        Next
        For i = 0 To 19
            For j = 0 To 19
                If i <> j And names(i) = Range("A1").Offset(j, 0) Then
                     MsgBox ("Duplicate entry at A" & i + 1 & " and A" & j + 1)
                End If
            Next
        Next
    Last edited by MonkeyF0cker; 04-02-12 at 07:42 PM. Reason: This repeats notification of same duplicate.. not sure if that's an issue
    Points Awarded:

    Justin7 gave MonkeyF0cker 100 SBR Point(s) for this post.


  5. #5
    Justin7
    Justin7's Avatar Become A Pro!
    Join Date: 07-31-06
    Posts: 8,577
    Betpoints: 1506

    Thanks. The code seems straight forward enough... But I've actually never done macro work in Excel.

    Basic question: how do I turn that code into a macro (or even a formula that checks whenever the sheet updates)?

  6. #6
    MonkeyF0cker
    Update your status
    MonkeyF0cker's Avatar Become A Pro!
    Join Date: 06-12-07
    Posts: 12,144
    Betpoints: 1127

    That code repeats the same match.

    I edited it to stop the repeat but it would have required some other sort of check in addition to what I added.

    So it's back to the original.

  7. #7
    MonkeyF0cker
    Update your status
    MonkeyF0cker's Avatar Become A Pro!
    Join Date: 06-12-07
    Posts: 12,144
    Betpoints: 1127

    Quote Originally Posted by Justin7 View Post
    Thanks. The code seems straight forward enough... But I've actually never done macro work in Excel.

    Basic question: how do I turn that code into a macro (or even a formula that checks whenever the sheet updates)?
    http://www.anthony-vba.kefra.com/vba/vbabasic1.htm

  8. #8
    MonkeyF0cker
    Update your status
    MonkeyF0cker's Avatar Become A Pro!
    Join Date: 06-12-07
    Posts: 12,144
    Betpoints: 1127

    Not sure how you want to implement it. You could add it to a button click or just run a macro.

    That link shows you how to setup a macro.

  9. #9
    Justin7
    Justin7's Avatar Become A Pro!
    Join Date: 07-31-06
    Posts: 8,577
    Betpoints: 1506

    Thanks again.

  10. #10
    thom321
    thom321's Avatar Become A Pro!
    Join Date: 06-17-11
    Posts: 112
    Betpoints: 4983

    If you don't have a lot of data you are comparing, you can create a function that works like a regular function in Excel (but slower) that checks a specified range for duplicates.

    I adjusted Monkeys code so the function returns the cell address(s) of any duplicate values.

    I have attached a workbook that has the function and some test data to show what it would return. You still need to know how to add macros in a workbook to include this in another workbook so I would still follow Monkeys suggestions.
    Attached Files

  11. #11
    edek
    edek's Avatar Become A Pro!
    Join Date: 07-30-11
    Posts: 1
    Betpoints: 3235

    quick and dirty

    put this in B1:B20

    =IF(COUNTIF($A$1:$A$20,A1)>1,"Duplicate","")

  12. #12
    a4u2fear
    TEASE IT
    a4u2fear's Avatar SBR PRO
    Join Date: 01-29-10
    Posts: 8,147
    Betpoints: 35459

    Quote Originally Posted by edek View Post
    put this in B1:B20

    =IF(COUNTIF($A$1:$A$20,A1)>1,"Duplicate","")
    1 post and 1140 pts?

  13. #13
    gino342
    gino342's Avatar Become A Pro!
    Join Date: 11-11-10
    Posts: 41

    perhaps i'm missing something but couldn't you simply use the remove duplicates feature under DATA? excel 2010.

  14. #14
    LT Profits
    LT Profits's Avatar Become A Pro!
    Join Date: 10-27-06
    Posts: 90,963
    Betpoints: 5179

    Seems to me this does not need to be as complicated as some are making it. Just put names alphabetical order in column A and insert column with basic IF statement in column B (i.e., IF(A2=A1,1,0)). As long as all returns are 0 you are fine.

  15. #15
    TomG
    TomG's Avatar Become A Pro!
    Join Date: 10-29-07
    Posts: 500

    There are lots of ways to do this. A macro should not be the first option, IMO.

  16. #16
    MonkeyF0cker
    Update your status
    MonkeyF0cker's Avatar Become A Pro!
    Join Date: 06-12-07
    Posts: 12,144
    Betpoints: 1127

    I'd much rather use a macro or some VBA routine than writing functions all over the sheet.

    You have one place to look (and one thing to modify) if you need to change something.

    To each his own I suppose. They all accomplish the same thing in the end.
    Last edited by MonkeyF0cker; 04-03-12 at 05:20 PM.

Top