+ Reply to Thread
Results 1 to 14 of 14

Get list of unique values from dynamic range

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-08-2015
    Location
    North Carolina USA
    MS-Off Ver
    MS Office 2016
    Posts
    368

    Get list of unique values from dynamic range

    Hi, I am trying to create a macro that will list the unique values from columns of data. (Usually between 2 and 5) This is easier to show than to explain - I have attached a workbook that has 3 columns of data, only 3 rows (the actual data is more) but the logic will be the same.

    You can see the result column basically goes through each value of column A and then combines it with the values of column B and C.. with the row count increasing 1 each time -- again, this will make more sense after looking at the example.

    Let me know if I need to clarify...

    Any help would be appreciated!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,301

    Re: Get list of unique values from dynamic range

    In your example, you should have had 27 (3*3*3) values. As long as each of your source columns (A, B, and C) don't have duplicates within them, then this code should work.

    Sub Test()
        Dim i As Long
        Dim j As Long
        Dim k As Long
        Dim r As Long
        
        r = 1
        Cells(r, "E").Value = "Result Column"
        For i = 1 To Cells(Rows.Count, "A").End(xlUp).Row
            For j = 1 To Cells(Rows.Count, "B").End(xlUp).Row
                For k = 1 To Cells(Rows.Count, "C").End(xlUp).Row
                    r = r + 1
                    Cells(r, "E").Value = Cells(i, "A").Value & Cells(j, "B").Value & Cells(k, "C").Value
                Next k
            Next j
        Next i
    End Sub
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Get list of unique values from dynamic range

    Basically, this sort of operation is called Caretesian Join.

    It can be easily be done using PowerQuery.

    Load all 3 ranges to PQ (you can use named range or Excel Table).

    To Table1 add custom column = Table2
    Then add another custom column = Table3

    Expand both custom columns.

    Resulting table.
    0.JPG

    See attached file.

    NOTE: You could add additional column to track logic if needed.
    Attached Files Attached Files
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,301

    Re: Get list of unique values from dynamic range

    I tried your instructions, but when I tried to add Table2 as a custom column to Table1, Excel did not like it. Are there step-by-step instructions, starting from a blank workbook, available anywhere that you would recommend?

  5. #5
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Get list of unique values from dynamic range

    maybe like this?

    custom.jpg
    Last edited by sandy666; 02-08-2018 at 06:30 PM.

  6. #6
    Forum Contributor
    Join Date
    08-08-2015
    Location
    North Carolina USA
    MS-Off Ver
    MS Office 2016
    Posts
    368

    Re: Get list of unique values from dynamic range

    This is great stuff guys - thank you!

  7. #7
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,301

    Re: Get list of unique values from dynamic range

    I did that, and after pressing OK, I get:

    Capture.JPG

  8. #8
    Forum Contributor
    Join Date
    08-08-2015
    Location
    North Carolina USA
    MS-Off Ver
    MS Office 2016
    Posts
    368

    Re: Get list of unique values from dynamic range

    This is great stuff guys - thank you! also - couldnt download that attachment, sandy

  9. #9
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Get list of unique values from dynamic range

    Quote Originally Posted by BG1983 View Post
    also - couldnt download that attachment, sandy
    this is a picture jpg. so you should see it in the post directly. refresh and try again

  10. #10
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Get list of unique values from dynamic range


  11. #11
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,301

    Re: Get list of unique values from dynamic range

    Thanks - that was a great help.

  12. #12
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Get list of unique values from dynamic range

    check here the name of tables then load all to the queries
    name of table you should see in workbook queries so use exactly the same name in Custom Column

    table.jpg

    btw. before load to the queries change headers to A, B and C or to any different not a column1, column1, column1
    Last edited by sandy666; 02-08-2018 at 07:00 PM.

  13. #13
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Get list of unique values from dynamic range

    This can also be done using MS Query.

    I did a post on it year or two ago in another forum.
    https://chandoo.org/forum/threads/ad...2/#post-176683

  14. #14
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Get list of unique values from dynamic range

    @Bernie

    or watch this one
    Attached Files Attached Files
    Last edited by sandy666; 02-08-2018 at 09:43 PM.

+ 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. dynamic list of unique values
    By td3201 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-14-2017, 12:38 AM
  2. Check range for values and return list of found unique values
    By kian82 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-13-2017, 04:45 AM
  3. [SOLVED] Count Unique Values in dynamic range when month is matched
    By MagicMan in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 06-08-2017, 06:04 AM
  4. A formula to sum unique values within a dynamic range
    By SoyBasedCheese in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-27-2016, 06:23 AM
  5. Dynamic Named Range with Unique Values Only for Sumproduct Function
    By tlscowden in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-16-2015, 03:16 PM
  6. [SOLVED] List unique values from multiple dynamic lists
    By andredl in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-22-2014, 02:37 AM
  7. Count Unique Values in Dynamic Range
    By Gos-C in forum Excel General
    Replies: 3
    Last Post: 01-19-2011, 01: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