+ Reply to Thread
Results 1 to 9 of 9

Extract unique values from range

  1. #1
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Extract unique values from range

    Hi all,

    I have a range with a maximum of 3 distinct values. How can I extract these 1-3 values with VBA and sort them at the same time?

    e.g.

    Column A

    SS17
    SS17
    SS17
    SS18
    SS18
    SS18
    SS19
    SS19

    Then I want my code to store these 3 values in ascending order and assign them to a variable.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,957

    Re: Extract unique values from range

    Not sure if this is what you mean...
    Please Login or Register  to view this content.
    Last edited by Sintek; 09-26-2018 at 07:26 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: Extract unique values from range

    hmm... this doesn't seem to be feasible in my data set as I am already using a filter. Also, I need to assign the 3 values to 3 different variables as I am using it for something else within my code.
    Attached Files Attached Files
    Last edited by esbencito; 09-26-2018 at 11:09 PM.

  4. #4
    Registered User
    Join Date
    03-11-2009
    Location
    BeiJing,China
    MS-Off Ver
    Excel 2016
    Posts
    11

    Re: Extract unique values from range


  5. #5
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Extract unique values from range

    Try to use formula
    Enter in B2 and copy down
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    v A B
    1
    2 SS17 SS17
    3 SS17 SS18
    4 SS17 SS19
    5 SS18
    6 SS18
    7 SS18
    8 SS19
    9 SS19
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,920

    Re: Extract unique values from range

    Please Login or Register  to view this content.
    Ben Van Johnson

  7. #7
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,957

    Re: Extract unique values from range

    hmm... this doesn't seem to be feasible in my data set
    Obviously you would have had to make changes to accommodate your data set
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: Extract unique values from range

    Thanks all! I ended up with a mix of both solutions and it seems to work just fine!

    Please Login or Register  to view this content.
    Didn't know that the advanced filter method is common to use in VBA to find unique values. It's probably even a lot faster than some of the other array calculations...
    Last edited by esbencito; 09-27-2018 at 01:40 AM.

  9. #9
    Forum Contributor
    Join Date
    03-23-2015
    Location
    Manila, Philippines
    MS-Off Ver
    2016
    Posts
    201

    Re: Extract unique values from range

    Quote Originally Posted by AlKey View Post
    Try to use formula
    Enter in B2 and copy down
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    v A B
    1
    2 SS17 SS17
    3 SS17 SS18
    4 SS17 SS19
    5 SS18
    6 SS18
    7 SS18
    8 SS19
    9 SS19

    *deleted.. apologies
    Last edited by EXCELBENCH; 09-30-2018 at 12:24 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. Replies: 11
    Last Post: 10-27-2016, 07:33 PM
  2. [SOLVED] Extract Unique values in range
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-08-2014, 06:39 AM
  3. Replies: 2
    Last Post: 02-13-2013, 03:14 PM
  4. Replies: 3
    Last Post: 11-24-2011, 06:11 AM
  5. Replies: 3
    Last Post: 09-20-2011, 05:05 PM
  6. Extract Unique Values, Then Extract Again to Remove Suffixes
    By Karl Burrows in forum Excel General
    Replies: 23
    Last Post: 06-25-2005, 08:05 PM

Tags for this Thread

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