none
sort array/collection RRS feed

  • Question

  • I would like to create a proc that sorts an array or collection. I have been able to create a collection with only unique values and now I need to be able to sort the list of unique values. I vb you get a sort method on arrays but vba doesn't do that.
    bdpb
    Wednesday, March 30, 2011 1:36 PM

Answers

  • Hi bdpb,

    I found this article on sorting with VBA

    http://www.cpearson.com/excel/SortingArrays.aspx

    Hope it helps


    Regards
    • Marked as answer by Bruce Song Monday, April 11, 2011 9:15 AM
    Wednesday, March 30, 2011 4:40 PM
  • Hello,

    If you use VBA in Word and want a simple sort function for arrays, you can use the old WordBasic sort function, like this;

        Dim aNames(3) As String
       
        aNames(0) = "Xero"
        aNames(1) = "Zorro"
        aNames(2) = "Johnny"
        aNames(3) = "Adam"
       
        WordBasic.SortArray aNames

    Sometimes the old WordBasic functions are blistering fast compared to the normal Automation API calls, especially when working with FormFields.

    Regards,
    Lars-Eric

    • Marked as answer by JPL_GDoL Thursday, April 28, 2011 9:27 PM
    Thursday, April 28, 2011 9:09 PM

All replies

  • Hi bdpb,

    I found this article on sorting with VBA

    http://www.cpearson.com/excel/SortingArrays.aspx

    Hope it helps


    Regards
    • Marked as answer by Bruce Song Monday, April 11, 2011 9:15 AM
    Wednesday, March 30, 2011 4:40 PM
  • Hi Bdpb,

    Have you resolved your issue yet, and does the suggestion help you? If you still have any concern on the thread, feel free to follow up.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, April 5, 2011 6:51 AM
  • Yeah, the link Rich provided was helpful.
    bdpb
    Thursday, April 28, 2011 1:44 PM
  • Hello,

    If you use VBA in Word and want a simple sort function for arrays, you can use the old WordBasic sort function, like this;

        Dim aNames(3) As String
       
        aNames(0) = "Xero"
        aNames(1) = "Zorro"
        aNames(2) = "Johnny"
        aNames(3) = "Adam"
       
        WordBasic.SortArray aNames

    Sometimes the old WordBasic functions are blistering fast compared to the normal Automation API calls, especially when working with FormFields.

    Regards,
    Lars-Eric

    • Marked as answer by JPL_GDoL Thursday, April 28, 2011 9:27 PM
    Thursday, April 28, 2011 9:09 PM
  • Perfect!

    Thanks Lars-Eric


    bdpb
    Thursday, April 28, 2011 9:27 PM