• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Sort words from the end

P

Pampos

Guest
Hello. I want, for example, to sort

big house
small tree
red cat
green house

alphabetically but start from the last letter.

For example, the result must be

small tree
big house
green house
red cat

Is that possible with excel? I already tried =RIGHT(A1,1) but is doesn't help me for the purpose I want the sorting.

Do you know if it is easier to do that in word?

Thanks
 
Hi ,

It is easy if you use VBA ; is that an option ?

If yes , then see the attached file.

Narayan
 

Attachments

  • Book2.xlsm
    14 KB · Views: 3
You can add a user-defined function such as Reverse which will take your strings and reverse them. Then you can sort on that new column. See attached which has such a function but I have left it unsorted, ready for you to do a standard sort on column B.
Before:
upload_2017-8-11_14-44-52.png

After:
upload_2017-8-11_14-45-59.png

And the code for that function:
Code:
Function Reverse(TheString)
For i = Len(TheString) To 1 Step -1
  Reverse = Reverse & Mid(TheString, i, 1)
Next i
End Function
 

Attachments

  • Chandoo35429.xlsm
    15.9 KB · Views: 5
I positively knew there was a shorter UDF I could write when I put forward my offering earlier. Here it is:
Code:
Function Reverse(TheString)
Reverse = StrReverse(TheString)
End Function
 
Back
Top