+ Reply to Thread
Results 1 to 3 of 3

VBA code to Split and Sort String Values

  1. #1
    Forum Contributor
    Join Date
    09-20-2014
    Location
    India
    MS-Off Ver
    2013
    Posts
    275

    VBA code to Split and Sort String Values

    Dear Excel Experts
    I have a VBA code to loop through a column of 10K rows and store unique values in it. These unique values are basically years like 2018,2019,2020,2021 etc..

    When i store unique values, the list is pretty much random like 2022,2019,2021,2018 etc (its because the original data itself is not sorted as per year.)
    Is there any way that i can sort the data in ascending order of years after pulling unique values. I am adding this list to data validation later.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,420

    Re: VBA code to Split and Sort String Values

    Here is a function that will take a range of cells and return the unique values in that sorted (this takes the place of the loop you showed part of above). So, if you wanted to assign the output to a variable named unique_string for the range of cells, say, C1:C10000, you would do this...

    unique_string = Sorted(Range("C1:C10000"))

    which, if the range C1:C10000 will never change, can be short-cutted to this...

    unique_string = Sorted([C1:C10000])

    Note: The Sorted function has an optional second argument allowing you to specify the delimiter to use which defaults to a comma if omitted.

    Here is the function (put it in a General Module)...
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    09-20-2014
    Location
    India
    MS-Off Ver
    2013
    Posts
    275

    Re: VBA code to Split and Sort String Values

    Does its Job perfectly...Many Thanks for your code..!!

+ 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] Split a String into 5 values
    By nironto in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-16-2017, 04:22 AM
  2. [SOLVED] Vb Code to split and sort data
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2016, 09:08 PM
  3. [SOLVED] split and sort a string
    By se3unlock in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-18-2015, 04:38 AM
  4. [SOLVED] VBA code required to TRIM and SPLIT the selected Range (String)
    By mchilapur in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-20-2015, 04:04 AM
  5. Replies: 1
    Last Post: 04-12-2014, 04:03 PM
  6. VB Code to split the text String
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-25-2013, 10:21 AM
  7. Split String into Cells with incased values []
    By ezykiwi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-26-2008, 07:52 AM

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