+ Reply to Thread
Results 1 to 5 of 5

Macro to find cell value in column and retrieve duplicates

  1. #1
    Registered User
    Join Date
    02-03-2014
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    23

    Macro to find cell value in column and retrieve duplicates

    So I have the macro written, but I don't get the complete data that I am looking for.
    This is what I am trying to achieve

    Here is an example of what i am trying to achieve
    This is in the first sheet:
    Column A Column B
    Car Saw
    Dew Jacket
    Pen Key
    Saw Screen
    Hand Shoe
    Jacket Window
    Screen Sock
    Screen Mouse


    Now I want this in the next sheet:
    Column A Column B Column C Column D
    Car Saw Screen Sock
    Car Saw Screen Mouse
    Dew Jacket Window
    Pen Key
    Saw Screen Sock
    Hand Shoe
    Jacket Window
    Screen Sock
    Screen Mouse

    In my current macro, It displays most of what I am looking for, but not a duplicate ID if there is one. For example Screen, there are 2 IDs. My macro is only getting the first one and then skipping over the second ID. I would like it to where if there is a double or if it is there more than once that it gets all of the data.

    Here is my macro.
    Please Login or Register  to view this content.
    I will also attach the document of what I am looking for. Thanks for your help!
    Attached Files Attached Files

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,626

    Re: Macro to find cell value in column and retrieve duplicates

    Here
    Please Login or Register  to view this content.
    you shall take into account that
    Please Login or Register  to view this content.
    could mean that in data can be one OR MORE entries of search_str in coulmn A of your data.

    As a matter of fact I do not think it is a good idea to use dictionary object here. Note that in your data there is only 31 unique values in column A so in dictionary you will have only 31 items.

    also - in post text you missed one row of output
    Column A Column B Column C Column D
    Car Saw Screen Sock
    Car Saw Screen Mouse
    Dew Jacket Window
    Pen Key
    Saw Screen Sock
    Saw Screen Mouse
    Hand Shoe
    Jacket Window
    Screen Sock
    Screen Mouse
    Last edited by Kaper; 03-04-2014 at 05:36 PM.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    02-03-2014
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Macro to find cell value in column and retrieve duplicates

    Thanks for you input Kaper, but I still don't know what to do to get the duplicates. If not dictionary, then what?

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,626

    Re: Macro to find cell value in column and retrieve duplicates

    The idea colld be illustrated with:
    Please Login or Register  to view this content.
    Check how it works with all 3 sheets of sample data.

    key points are:
    working until there is something in recently completed column
    Please Login or Register  to view this content.
    going down-up in desults sheet to easily add rows (rows below move down, but in next step we are anyway a row up, so dont't care abou what happened below
    Please Login or Register  to view this content.
    finding not one, but all :
    Please Login or Register  to view this content.
    instances of predcessor in column A of source
    Please Login or Register  to view this content.
    (match range is from one below found in previous step till the end of data.

    Of course you can now finetune it, add columns widths etc. but the algorithm shall work fine. May be look for more efficient data structures, because here all processing occurs in the spreadsheet.

    Final comment: I added a security check
    Please Login or Register  to view this content.
    to let user intervene in case of looped data like

    HTML Code: 
    Long post, isn't it?
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    02-03-2014
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Macro to find cell value in column and retrieve duplicates

    Thank you so much!!! I appreciate your time and effort! The code works flawlessly!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Coding to Find Cell and Retrieve Row and Column Numbers
    By chaplaindoug in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2013, 01:18 PM
  2. [SOLVED] Macro to find column with duplicates, for each of those check another column for duplicate
    By MaartenKoller in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-17-2013, 10:09 AM
  3. Macro to find duplicates in columns and then list them in a new column
    By RainbowLettering in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-04-2013, 11:03 PM
  4. [SOLVED] Macro to find and retrieve cell contents
    By DancingElvisLives in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-31-2011, 09:33 AM
  5. macro to find duplicates in 1 column
    By vsantoro in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-01-2011, 05:20 PM

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