+ Reply to Thread
Results 1 to 11 of 11

function or sub to dedect doubles

  1. #1
    Registered User
    Join Date
    05-11-2007
    Location
    Belgium
    Posts
    68

    function or sub to dedect doubles

    I have a column with employee id's. Sometimes two or more employee ID's are double. I need to dedect if there are ID numbers that appears more then ones. If I found such a number I can copy that.
    Has someone an idea or is there a build in function to handle this ?

    Please Login or Register  to view this content.
    the code should detect :
    604168 (appears tree times).

  2. #2
    Forum Expert oldchippy's Avatar
    Join Date
    02-14-2005
    Location
    Worcester, UK
    MS-Off Ver
    Excel 2007 (Home)
    Posts
    7,097
    You could try this in B1, and drag it down as far as data in column A

    =COUNTIF($A$1:$A$5,A1) adjust the range to your range of numbers. Where there is one, 1 will appear, or 3 in this case
    oldchippy
    -------------


    Blessed are those who can give without remembering and take without forgetting

    If you are happy with the help you have received, please click the <--- STAR icon on the left - Thanks.

    Click here >>> Top Excel links for beginners to Experts

    Forum Rules >>>Please don't forget to read these

  3. #3
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    See the attached file. I added macro 'Macro1' to do what you ask.

    I hope it's what you need.

    Regards,
    Antonio

  4. #4
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    I'm sorry... I forgot to insert attachment file.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    05-11-2007
    Location
    Belgium
    Posts
    68

    zip

    ok, thanks Antonio, the company policies forbit to open the attachment
    I check it at home and let you know.

  6. #6
    Forum Expert oldchippy's Avatar
    Join Date
    02-14-2005
    Location
    Worcester, UK
    MS-Off Ver
    Excel 2007 (Home)
    Posts
    7,097
    Here's a link you may find useful?

    http://www.cpearson.com/excel/duplicat.htm

  7. #7
    Registered User
    Join Date
    05-11-2007
    Location
    Belgium
    Posts
    68

    countif

    Please Login or Register  to view this content.
    CountIf seems to be a worksheet function. So he can't execute this code.

    Antonio, I saw your code, it works fine in your example. I just try to find out how it works.

    Please Login or Register  to view this content.

    C[-1],RC[-1]) = here you define the range. Is C[-1] the previous column and what is RC[-1] ?

  8. #8
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    The formula use relative references with RC (row and column).

    To understand the formula, for example, if I put formula in Range B2 it will appear so:
    IF(COUNTIF(A:A;A2)>1;"Appears " & COUNTIF(A:A;A2) & " times";"")

    If you start macro recorder, go on cell with formula (f.ex. B2), press 'F2' and then enter, stop macro recorder and go to see what Excel has recorded you will see exactly the formula I applied on the macro.

    Regards,
    Antonio

  9. #9
    Registered User
    Join Date
    05-11-2007
    Location
    Belgium
    Posts
    68

    worksheet function <> vba function

    I have the idea vba does not allowed you to use the worksheet function COUNTIF. Only if you use vba to past it, use the function in your worksheet.
    Because I don't want to run the result of the duplicate entries check in my worksheet I think I can't use the COUNTIF function.
    Is there an equivalent function to use in your vba or do I just loop the whole column and use an counter ? Perhaps not the best way ?

  10. #10
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    I'm sorry but I don't understand what you exactly need.

    Do you want only maintain no duplicated rows? Or do you prefer only put string 'Appears x times' only at the first occurence of it?

    Regards,
    Antonio

  11. #11
    Registered User
    Join Date
    05-11-2007
    Location
    Belgium
    Posts
    68

    ok

    no problem.
    I used COUNTIF succesfully by your suggestion. However this works fine if you paste your formula in your sheet. If you are not allowed to past this in your sheet (e.g user is not allowed to change structure) you can not work with COUNTIF. COUNTIF is a worksheet function.

+ 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