+ Reply to Thread
Results 1 to 18 of 18

Extract unique values from 2 columns DYNAMICALLY

  1. #1
    Registered User
    Join Date
    08-24-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Extract unique values from 2 columns DYNAMICALLY

    Hey!

    I have two table columns which I need to merge the data from. Duplicates must be removed and the new list must be able to dynamically update itself when new entries are made.

    I know this can be achieved with simple copy/paste & remove duplicates or with Advanced Filter -> Copy unique values, but these require a macro to be hassle-free.

    Is there a formula I can use the extract the unique values dynamically?

    Test.xlsx

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,723

    Re: Extract unique values from 2 columns DYNAMICALLY

    This site explains how you can extract a list of uniques from two lists:

    http://www.get-digital-help.com/2009...array-formula/

    Define List1 and List2 as dynamic ranges if you will be adding data to them frequently.

    Hope this helps.

    Pete

  3. #3
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Extract unique values from 2 columns DYNAMICALLY

    Hi Albatr0n

    See the attached file where I have used a pivot table to achieve the desired results.. thanks.

    Test(14).xlsx

    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), [email protected]

  4. #4
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Extract unique values from 2 columns DYNAMICALLY

    Try this file.

    Run macro1
    Attached Files Attached Files
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  5. #5
    Registered User
    Join Date
    08-24-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Extract unique values from 2 columns DYNAMICALLY

    @Pete_UK

    Thanks a lot for the link Pete. I was looking into something similar, but it's a bit hard for me to decipher what's going on, because I am not familiar with most of these functions.

    @oeldere

    Thank you for taking the time to respond with a viable solution. The problem is I have to avoid using macros.

    @dilipandey

    Just when I gave up trying to do this with a PivotTable, you did it! What you have managed to achieve is precisely what I have been trying to do for days with the Wizard but to no avail.

    Can you please explain what principles you use when you consolidate multiple ranges for PivotTable display? Can you use this same method for merging table columns?

    Thanks a lot!

  6. #6
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Extract unique values from 2 columns DYNAMICALLY

    Hi Albatr0n,

    I have used a defined name (press Ctrl + F3 to see that) in the pivot table and that's it...

    Regards,
    DILIPandey

    <click on below 'star' if this helps>

  7. #7
    Registered User
    Join Date
    08-24-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Extract unique values from 2 columns DYNAMICALLY

    EDIT: dillpaney, I am sorry, but the PivotTable method doesn't seem to work.

    To test for yourself, in your workbook "Test(14)" please enter a value in column2 that's non-existant in column1, then click refresh. The new value will not be entered as a new row in the PivotTable, because the Pivot apparently recognizes the second column as "Values" and column1 as "Rows". No merging of the two columns actually takes place.

    In this attachment, I have used "ss" as a new entry in column2 as a logic test.

    Sadly, a PivotTable simply can't merge two columns into a single row for representation.

    Test(14)-ss.xlsx
    Last edited by albatr0n; 08-25-2012 at 10:09 AM.

  8. #8
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Extract unique values from 2 columns DYNAMICALLY

    Yes.. albatr0n

    I think you should go for macro (vba) solution.. thanks.

    Regards,
    DILIPandey

    <click on below 'star' if this helps>

  9. #9
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,723

    Re: Extract unique values from 2 columns DYNAMICALLY

    Hi Albatr0n,

    Quote Originally Posted by albatr0n View Post
    Thanks a lot for the link Pete. I was looking into something similar, but it's a bit hard for me to decipher what's going on, because I am not familiar with most of these functions.
    The site does list the four functions that the formula uses, but in case you need a formula-based solution I have set this up in the attached file. I've created two dynamic named ranges called To and From and then put this array* formula in D2:

    =IFERROR(IFERROR(INDEX(To, MATCH(0, COUNTIF($D$1:D1, To), 0)), INDEX(From, MATCH(0, COUNTIF($D$1:D1, From), 0))), "")

    and then copied it down to D15 - copy it further if you need to.

    As you enter new names in either the To or From columns, column D will give a list of the unique names in both lists.

    *An array formula needs to be committed using the key combination of Ctrl-Shift-Enter instead of the usual Enter.

    Hope this helps.

    Pete
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    08-24-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Extract unique values from 2 columns DYNAMICALLY

    Thanks a lot for the workbook example, Pete! The formula works, but I realized that I also need to sort alphabetically.

    Basically, I need an array formula that does this:

    1. Look into this range of two columns.
    2. Find and extract all unique values.
    3. List them in that column alphabetically.

    I've seen some spreadsheet applications have a very simple way of doing this: E.g.

    =UNIQUE(array)

    will return only unique values in a list.

    A simliar function doesn't seem to exist in Excel. What do you think would be the most elegant solution to do this?

    Thanks.

    P.S. Would have replied sooner, but the board went dead for a day or two.
    Last edited by Cutter; 08-27-2012 at 03:21 PM. Reason: Removed whole post quote

  11. #11
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,723

    Re: Extract unique values from 2 columns DYNAMICALLY

    It is possible to sort by formulae, but it would need to be done in a separate column (you could hide the column with the unique list in it, so that it would look the same).

    As for a function like UNIQUE, well it is possible to write user-defined functions in Excel, so that array formula that I gave you could possibly be converted into such a function.

    Hope this helps.

    Pete

  12. #12
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Extract unique values from 2 columns DYNAMICALLY

    or you use a macro (see #4).

  13. #13
    Valued Forum Contributor
    Join Date
    07-29-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003/Excel 2010
    Posts
    534

    Re: Extract unique values from 2 columns DYNAMICALLY

    Example of a user defined function like Pete suggests.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    08-24-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Extract unique values from 2 columns DYNAMICALLY

    Thanks for chipping in, guys. The problem is I have to avoid using macros in my sheets; that's why I always look for alternatives first.

    I found this formula which pretty much nails it. If it could be simplified and integrated in Excel for quick input, it would be awesome!

  15. #15
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,723

    Re: Extract unique values from 2 columns DYNAMICALLY

    That's another one from Oscar's site. Are you saying that you don't know how to apply it to your file?

    Pete

  16. #16
    Registered User
    Join Date
    08-24-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Extract unique values from 2 columns DYNAMICALLY

    No, Pete, I can apply it and change the range, but if the function could be converted to something like:

    =EXTRACTU(data_range,output_range,[other parameters])

    now that would be fantastic, as it can be applied very quickly without having to rename ranges and tweak the formula every time.

    Is this what you meant by "user-defined functions"? Can they be made that flexible?
    Last edited by Cutter; 08-28-2012 at 12:06 PM. Reason: Removed whole post quote

  17. #17
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,723

    Re: Extract unique values from 2 columns DYNAMICALLY

    A user-defined function (UDF) is written in VBA, and thus is a type of macro - but you've said that you want to avoid macros !!

    I'm not sure why you would need to tweak the ranges in that formula once it is set up. If it refers to an Excel Table (which automatically adjusts to new entries, rather like my dynamic ranges earlier), then it should be okay. Also, if you put IFERROR( .... ,"") around it then you can copy it down much further than you would need and it would still function properly.

    Hope this helps.

    Pete

  18. #18
    Registered User
    Join Date
    08-24-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Extract unique values from 2 columns DYNAMICALLY

    The only thing that needs to be tweaked are the ranges really, but if I want to use the formula for multiple tables, I have to replace something like 20 references every time -- which is OK, I just hope that some day this would be turned into an integrated formula or at least greatly simplified.

    For now, that will do.

    Thanks.
    Last edited by Cutter; 08-28-2012 at 12:06 PM. Reason: Removed whole post quote

+ 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