+ Reply to Thread
Results 1 to 2 of 2

search for (but not delete) first duplicate value

  1. #1
    Registered User
    Join Date
    05-24-2012
    Location
    atlanta
    MS-Off Ver
    Excel 2010
    Posts
    45

    search for (but not delete) first duplicate value

    This is to locate a reference cell. The sheet has unformatted data at the top, and then a clean version of the data (blank rows removed) at the bottom. The row labels are unique, but they repeat.

    What I would like to do is to create a loop that runs down column B... in garbled high level language (more c++ than vba because its what I know) something like.

    for i=1, i<ws.usedrange.rows, i++
    {
    if (find (ws.row(i+1).value in rows(1,i)))
    break
    }
    msgbox "first duplicate value found in row"&(i+1)

    The idea is that it starts off comparing row 2 to rows 1:1, if it is not found in that range, it loops, then it compares row 3 to rows 1:2, and so on. When it first finds a duplicate in the previous range, it breaks the loop and (i+1) now equals the row of the duplicate value.

    ...

    I am trying to learn VBA right now, so I realize my language is terrible, my project outpaces my learning, the functions and syntax are giving me trouble, and its been years since I did C++, not that it translates in every way either.

    Any guidance you can give...

  2. #2
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: search for (but not delete) first duplicate value

    I'm not sure this will line up exactly with your query, but given your background, I would think this should get you going in the right direction.

    Assuming a source range in Column A with no blanks and a range to be searched in Column B:

    Please Login or Register  to view this content.
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

+ 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