+ Reply to Thread
Results 1 to 18 of 18

sorting multi column listbox

  1. #1
    Registered User
    Join Date
    10-21-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    59

    sorting multi column listbox

    Dear All,

    I have listbox of 12 columns and 150 Rows. I need macro to sort listbox according to colummn 3 (which contains data of integers) and also need another macro which sort listbox according to column 2 (which contains data of string)


    Thanks in advance.
    Last edited by ali84pk; 11-12-2011 at 02:15 AM.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: sorting multi column listbox

    Hi ali84pk
    With a workbook maybe this link will help
    http://www.sqldrill.com/excel/progra...-vba-code.html
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Registered User
    Join Date
    10-21-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: sorting multi column listbox

    Quote Originally Posted by pike View Post
    Hi ali84pk
    With a workbook maybe this link will help
    http://www.sqldrill.com/excel/progra...-vba-code.html
    Dear Pike,

    thanks for help. It seems, that your provided code are exactly what I am looking for.
    I tried those code, but facing error of ByRef argument type mismatch. on "lst1"
    Please Login or Register  to view this content.
    can you please advice, what is reason.

    thanks

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: sorting multi column listbox

    Hi ali84pk,
    Can you attach the workbook?
    It makes it so much easier

  5. #5
    Registered User
    Join Date
    10-21-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: sorting multi column listbox

    Dear pike

    Please find attachment of file. I need one macro to sort listbox by
    "agent name" and one macro to sort by Amount".


    Thanks
    Attached Files Attached Files

  6. #6
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: sorting multi column listbox

    hi ali84pk,

    This will do the trick

    Please Login or Register  to view this content.
    Last edited by pike; 11-09-2011 at 01:25 AM.

  7. #7
    Registered User
    Join Date
    10-21-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: sorting multi column listbox

    Dear Pike

    Thanks for your all efforts :-), 50% of job is 100% done.

    I can sort as per agent column but not as per amount column.

    I have noticed, if I put value manually in amount column, it works fine in sorting as per amount column. But if I paste my original data, it gives error.

    I have pasted original data in example file so that you can see the error. Can you please assist on this.

    Once again thanks a lot. You have saved my a lot of time.

    Thanks
    Attached Files Attached Files

  8. #8
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: sorting multi column listbox

    Hi ali84pk

    change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    data mismatch

  9. #9
    Registered User
    Join Date
    10-21-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: sorting multi column listbox

    Dear Pike,

    Thanks for prompt reply. Error is solved but sorting is as per first digit only, not as per whole amount value

    Sorry to bother you

    Need your help again

    Thanks

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: sorting multi column listbox

    alternative

    Please Login or Register  to view this content.
    Last edited by snb; 11-10-2011 at 05:42 AM.



  11. #11
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: sorting multi column listbox

    hi ali84pk
    change this back to

    Please Login or Register  to view this content.
    and change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    the empty cells are causing the 13 error

  12. #12
    Registered User
    Join Date
    10-21-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: sorting multi column listbox

    Dear Snb,

    Thanks for your contribution in helping me. Actually in my project, I have to fill listbox in outlook form also. therefore I can't use this alternative approach. Please help me in modifying this approach in which I am almost done.

    Dear Pike,
    Problem is still same, it sorts amount column on base of first digit.
    for example:
    10
    200
    1000
    500

    macro sorts as :

    10
    1000
    200
    500

    Thanks

  13. #13
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: sorting multi column listbox

    ali84pk. In the Private Sub UserForm_Initialize() procedure, try this line
    Please Login or Register  to view this content.
    written as
    Please Login or Register  to view this content.

  14. #14
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: sorting multi column listbox

    You can always refer from Outlook to Excel using

    Please Login or Register  to view this content.
    or the other way around
    Please Login or Register  to view this content.

  15. #15
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: sorting multi column listbox

    Hmmm,, it works with the data
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    10-21-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: sorting multi column listbox

    Quote Originally Posted by pike View Post
    Hmmm,, it works with the data
    WOW!! Pike you are Superman!! .Thank you very much! for your all efforts.
    It's working like charm

    Thanks

  17. #17
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: sorting multi column listbox

    It also works with:

    Please Login or Register  to view this content.

  18. #18
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: sorting multi column listbox

    Hi ali84pk,
    snbs code will also work with out the need to add the zeros to empty cells.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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