+ Reply to Thread
Results 1 to 7 of 7

Sub to remove duplicate IDs and combine multiple lookup results into single cells

  1. #1
    Valued Forum Contributor
    Join Date
    09-07-2006
    Posts
    520

    Sub to remove duplicate IDs and combine multiple lookup results into single cells

    Looking for a sub to do this, thanks for any help

    Data in cols A and B in Sheet1 (Data is sorted by col A)
    ID_A Val_1
    ID_A Val_2
    ID_B Val_3
    ID_B Val_4
    etc

    Desired Output in a new sheet, cols A and B, with multiple results per ID separated by comma
    ID_A Val_1,Val_2
    ID_B Val_3, Val_4

  2. #2
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: Sub to remove duplicate IDs and combine multiple lookup results into single cells

    hi there. do upload an excel sample so that we do not have to manually key in your data to do a testing.

    try this code here:
    Please Login or Register  to view this content.
    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button
    Attached Files Attached Files

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  3. #3
    Valued Forum Contributor
    Join Date
    09-07-2006
    Posts
    520

    Re: Sub to remove duplicate IDs and combine multiple lookup results into single cells

    Thanks. The original data in columns A and B are all text numbers - long strings with several leading zeroes, eg:
    000100014007
    000100014008

    In Desired Results, the results seem to convert col A & B into real numbers, and column B has mixed results (some correct, some incorrect), it is also affected by the comma separator
    How could the above be overcome? I'm ok to use another separator ( but results should all be retained as textnumbers

  4. #4
    Valued Forum Contributor
    Join Date
    09-07-2006
    Posts
    520

    Re: Sub to remove duplicate IDs and combine multiple lookup results into single cells

    Am not able to upload sample file, but here's the sample data

    Data
    002000208886 000100011007
    002000208886 000100014001

    Desired Output, with colon ( as separator
    002000208886 000100011007:000100014001
    Max
    Singapore

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Sub to remove duplicate IDs and combine multiple lookup results into single cells

    Try this to start with.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by bakerman2; 10-19-2017 at 03:28 AM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  6. #6
    Valued Forum Contributor
    Join Date
    09-07-2006
    Posts
    520

    Re: Sub to remove duplicate IDs and combine multiple lookup results into single cells

    Many thanks, bakerman2. Works well, and noticed that Column A data does not need to be pre-sorted

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Sub to remove duplicate IDs and combine multiple lookup results into single cells

    You're welcome and thanks for rep+.

+ 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. [SOLVED] Need to combine cells to one string of text if duplicate values exist in multiple cells
    By Chris McGlothen in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-17-2017, 09:13 PM
  2. Sort Query Results to remove duplicate entries and put results on one line.
    By Panther70 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-01-2015, 03:03 PM
  3. [SOLVED] Combine Multiple sections into single cells
    By flexi1 in forum Excel General
    Replies: 9
    Last Post: 02-23-2015, 09:30 AM
  4. [SOLVED] Combine multiple ALMOST duplicate rows into a single row
    By Styler001 in forum Excel General
    Replies: 3
    Last Post: 07-31-2014, 02:30 AM
  5. Replies: 1
    Last Post: 09-06-2013, 10:05 AM
  6. Replies: 8
    Last Post: 04-12-2012, 08:02 PM
  7. [SOLVED] lookup multiple values of a single cell and return sum of results
    By Zeppelin17 in forum Excel General
    Replies: 7
    Last Post: 08-10-2011, 07:09 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