+ Reply to Thread
Results 1 to 10 of 10

Sorting array on the basis of Length of element

  1. #1
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Sorting array on the basis of Length of element

    Hi,

    One combobox is populated from an array of string

    Please Login or Register  to view this content.
    And ItemList is the list of unique items taken from an ongoing column

    ("Itemmmm,Itemm,Itemmm,Item")

    Need it to be
    ("Item,Itemm,Itemmm,Itemmmm")


    Can't sort it on the sheet

    I am getting the unique list from D column with a dictionary way.

    Thanks in advance
    Teach me Excel VBA

  2. #2
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Sorting array on the basis of Length of element

    Your example implies that you just need to reverse the list, if you can't sort the original list, how about another column to sort it, then populate the combobox from the new column?

    =INDEX(ItemList,ROWS(ItemList)-ROWS(A$1:A1)+1)

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,888

    Re: Sorting array on the basis of Length of element

    How about
    Please Login or Register  to view this content.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Sorting array on the basis of Length of element

    Or you could sort it (by length) after it is filled

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Re: Sorting array on the basis of Length of element

    @jason thanks but I don't want to reverse the list, I want to sort the Combobox items in place. Your solution did contributed to one of my older threads here.


    @Fluff Thanks your solution is working as required.

    @mike Thanks for your solution too, but I have a combobox on the userform and not listbox. Secondly how should I pass this?

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,888

    Re: Sorting array on the basis of Length of element

    You're welcome & thanks for the feedback

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Sorting array on the basis of Length of element

    Quote Originally Posted by ImranBhatti View Post

    @mike Thanks for your solution too, but I have a combobox on the userform and not listbox. Secondly how should I pass this?
    ComboBox and list boxes are almost identical, other than changing to AList box to type MSForms.ComboBox1, nothing more is needed.

  8. #8
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,785

    Re: Sorting array on the basis of Length of element

    Thanks mike I did changed but I mean how should I pass the parameters

    Me.ComboBox1.list = ?

    Me.ComboBox1.List = SortLBbyLength(Me.CombBox1.List)? or something else?

  9. #9
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: Sorting array on the basis of Length of element

    I used it like this and worked ok

    Please Login or Register  to view this content.
    Last edited by nigelog; 01-21-2019 at 12:13 PM.

  10. #10
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Sorting array on the basis of Length of element

    Quote Originally Posted by ImranBhatti View Post
    Thanks mike I did changed but I mean how should I pass the parameters

    Me.ComboBox1.list = ?

    Me.ComboBox1.List = SortLBbyLength(Me.CombBox1.List)? or something else?
    Fill Combobox1 and then call the Sub

    Please Login or Register  to view this content.

+ 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. Does current Array Element Contain Text from Another Array?
    By TheRobsterUK in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-17-2018, 11:30 AM
  2. Replies: 12
    Last Post: 01-14-2014, 01:56 PM
  3. [SOLVED] Read last element of Split array and then discard it and resize the array.
    By staggers47 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-28-2012, 06:36 PM
  4. [SOLVED] Returning an array specific to an element of a separate array
    By peterszabla in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-24-2012, 05:30 PM
  5. Sorting Items by Length for a target length list.
    By Joe Bob Crain in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-06-2006, 12:46 PM
  6. Array problem: Key words-Variant Array, single-element, type mismatch error
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-09-2005, 01:54 AM
  7. Array problem: Key words-Variant Array, single-element, type mismatch error
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2005, 12:30 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