Consulting

Results 1 to 3 of 3

Thread: Sorting arrays

  1. #1
    VBAX Regular
    Joined
    Feb 2015
    Posts
    79
    Location

    Sorting arrays

    Good morning VBA masters,

    I have a userform that 大灰狼1976 so graciously redesigned for me. I am new to arrays and would like the arrays being presented in the combo boxes to be sorted in ascending order.

    I have scoured the internets with no luck. Attached is the file I am working with. Any help is greatly appreciated.

    If you have time or links, I would like to learn "how" to do this as well.

    Again thank you.

    MaterialStore.xlsmChunk

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    'http://www.cpearson.com/excel/SortingArrays.aspx

    QSortInPlace





    Option Explicit
    Public arrMst As Variant, dMst As Object, dTmp As Object
    Private Sub UserForm_Activate()
        Dim i As Long, s As String
        Dim v() As Variant
        
        arrMst = Sheets("data").[a1].CurrentRegion
        
        Set dMst = CreateObject("scripting.dictionary")
        Set dTmp = CreateObject("scripting.dictionary")
        
        For i = 2 To UBound(arrMst)
          s = arrMst(i, 4)
          dMst(s) = dMst(s) & "," & arrMst(i, 2)
          dTmp(s) = dTmp(s) & "," & i
        Next i
        
        v = dMst.keys        ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        Call QSortInPlace(v)
        cbo_proj.List = v
    
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Hi Chunk!
    If the actual data of "PROJECT" is large and complex, In addition to sorting,
    there is another way, you can enter part of "PROJECT" in cbo_proj and try it out.
    Please refer to the attachment.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •