+ Reply to Thread
Results 1 to 8 of 8

Sort List based on Permutation

Hybrid View

  1. #1
    Registered User
    Join Date
    12-16-2008
    Location
    malaysia
    Posts
    5

    Sort List based on Permutation

    Hi,

    I'm new here, google helped me to find this place. Hope someone here can help me a bit on my excel spreadsheet. I have one list of numbers and it need to be sorted under Perm condition so the list become shorter. The function should go through the listed number and output new list after sorting it. I have attached my excel here.

    Thanks for any help,

    Regards,
    Subashr
    Attached Files Attached Files
    Last edited by subashr; 12-18-2008 at 01:08 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Not sure if this is what you mean. The function below converts "4824" to "2448". You can filter to remove duplicates.
    Function AnaSort(sInp As String, Optional bUniq As Boolean = False) As String
        ' Returns the characters of sInp in alpha order: AnaSort("amaze") = "aaemz"
        ' with option to return unique characters only:  AnaSort("amaze", True) = "aemz"
    
        Dim i       As Long             ' index to string characters
        Dim aiNum(0 To 255) As Long     ' count of characters by code
        Dim iAsc    As Long             ' index to aiNum
    
        For i = 1 To Len(sInp)
            iAsc = Asc(Mid(sInp, i, 1))
            aiNum(iAsc) = aiNum(iAsc) + 1
        Next
    
        If bUniq Then
            For iAsc = 0 To 255
                If aiNum(iAsc) Then AnaSort = AnaSort & Chr$(iAsc)
            Next
        Else
            For iAsc = 0 To 255
                AnaSort = AnaSort & String$(aiNum(iAsc), Chr$(iAsc))
            Next
        End If
    End Function
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    12-16-2008
    Location
    malaysia
    Posts
    5
    Thanks for the codes. I'm not good in VBA here, this code looks complex to me.I can understand this code but not sure how to pass the parameters it requires in excel and get it out as output. I don't know how to execute this code on my sheet. Could you add in for me please?

    Thanks again for your help.

    Regards,
    Subashr

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    In B2: =AnaSort(A2) and copy down.

  5. #5
    Registered User
    Join Date
    12-16-2008
    Location
    malaysia
    Posts
    5
    Hi,

    I'm getting i get #NAME? error

    any help appreciated.

    regards,
    subashr

  6. #6
    Registered User
    Join Date
    12-16-2008
    Location
    malaysia
    Posts
    5
    i managed to get it right finally. thanks again for your kind help

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Would you please mark the 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

  8. #8
    Registered User
    Join Date
    12-16-2008
    Location
    malaysia
    Posts
    5
    Done.

    Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 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