+ Reply to Thread
Results 1 to 14 of 14

Sort for multicolumn listbox in userform (5-columns)

  1. #1
    Registered User
    Join Date
    08-16-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Office2011 (Mac)
    Posts
    16

    Sort for multicolumn listbox in userform (5-columns)

    Hi all,

    I have a multicolumn listbox in a userform that has 5 columns. As my dataset is growing, I need to allow users to sort the columns using command buttons placed above each column. I have found examples of how to sort 1 or 2 columns, but cannot find anything for 5 columns.

    The following is what I have used for a 2-column sort, and am curious if it can be modified to be used for a 5-colum sort.



    Please Login or Register  to view this content.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Sort for multicolumn listbox in userform (5-columns)

    This will do it for any number of columns.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    08-16-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Office2011 (Mac)
    Posts
    16

    Re: Sort for multicolumn listbox in userform (5-columns)

    Thank you, Andy. I appreciate your response.

    Does this now allow me to specify which column to sort by? At first glance, to my amateur eyes, it appears not.

    The other part of the challenge I face is the ability to specify the column to be sorted, and have a command button above each column to allow users to sort by those columns, respectively.

    -Dave

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Sort for multicolumn listbox in userform (5-columns)

    Yes it does. That is what the SortOn argument in the subs signature is.

    This example will sort the column you double click.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    08-16-2012
    Location
    Calgary, Alberta
    MS-Off Ver
    Office2011 (Mac)
    Posts
    16

    Re: Sort for multicolumn listbox in userform (5-columns)

    Wow, Impressive! Thank you so much for the file with a working sample. Implementing this will with my application will be fun.

  6. #6
    Registered User
    Join Date
    05-21-2013
    Location
    United States
    MS-Off Ver
    excel 2010
    Posts
    2

    Re: Sort for multicolumn listbox in userform (5-columns)

    That was Great! Thank you so much!

  7. #7
    Registered User
    Join Date
    04-15-2016
    Location
    Netherlands
    MS-Off Ver
    2010, 2013 and 2016
    Posts
    1

    Re: Sort for multicolumn listbox in userform (5-columns)

    Thank you for this code. This is really great.
    But I'm actually looking for a similar code to use in a listbox in Word in which I've loaded an Excel database.
    Can you help me out here, please?

    Thanks
    Kem

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

    Re: Sort for multicolumn listbox in userform (5-columns)

    Kem60,
    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    Ben Van Johnson

  9. #9
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Re: Sort for multicolumn listbox in userform (5-columns)

    Hello Andy,

    I was looking for a code to sort a multicolumn list box and i came across your double click feature which is really impressive!
    So i implemented my excel case into your double click idea but i noticed that the column that has dates doesn't get sorted properly.
    I uploaded a sample of my work.
    Please note that my userform-initialize to populate the list box is constructed differently than yours.

    Thanks!
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Re: Sort for multicolumn listbox in userform (5-columns)

    I think the issue lies when i loop through rows, not just the dates.
    Just wanted to clarify.

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Sort for multicolumn listbox in userform (5-columns)

    The sort is a bubble sort based on the textual content. In order to sort the dates properly you will need to sort their numeric values rather than the text in m/d/yyyy format.

    I have added a extra column, which you can hide using ColumnWidth of zero. When the 2nd column is sorted it uses the extra column values to actually sort on.
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    12-24-2014
    Location
    little ole England
    MS-Off Ver
    2013
    Posts
    116

    Re: Sort for multicolumn listbox in userform (5-columns)

    Quote Originally Posted by Andy Pope View Post
    The sort is a bubble sort based .
    first off all very nice work-a-round idea

    i am learning userforms by looking at examples and solutions

    in looking at this example 964420 i not that allthough it does everything OP required. for me it does not display the first row of your data sheet in the userform

    maybe i am doing something wrong

    regards
    ◄Ŧя?μвŁ?►
    By Name & By Nature

  13. #13
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Re: Sort for multicolumn listbox in userform (5-columns)

    Hi Andy,
    That's a very creative solution to the date issue, never would have come up with that on my own
    Thanks!

    Best,
    KB

  14. #14
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Sort for multicolumn listbox in userform (5-columns)

    @AkaTrouble. In order to display header in a listbox you need to use the rowsource property. This links the listbox directly with cells on the worksheet with the header row being the row immediately above the data. In order to sort the listbox you will need to sort the worksheet.

+ 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. Having problems populating a multicolumn listbox changing Listbox column with a loop.
    By Aristizabal95 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2013, 12:41 PM
  2. Transfer Data From One Userform Listbox to Another Userform Listbox with 11 columns
    By sparkoft in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-18-2013, 10:54 AM
  3. Copy Selected items from multicolumn, multiselect listbox to another listbox
    By Willigb in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-19-2013, 11:27 AM
  4. Multicolumn ListBox
    By pankaj2610 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-01-2013, 11:59 PM
  5. [SOLVED] Sort multicolumn listbox items?
    By Jens Meier in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-21-2005, 11:05 AM

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