ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Digits in ascending order ? (https://www.excelbanter.com/excel-worksheet-functions/69289-digits-ascending-order.html)

toyota58

Digits in ascending order ?
 
Hello,


Anyone knows how to sort digits in ascending order ?


Example :

Cell A1 = 3176
Cell A2 = 1367


Cell A1 = 704182
Cell A2 = 012478



Thank You.


[email protected]

Digits in ascending order ?
 
Hello,

I suggest to take this UDF:

Option Explicit

Function sort_digits(s As String) As String
Dim a(0 To 9) As Long, i As Long

For i = 1 To Len(s)
a(Mid(s, i, 1)) = a(Mid(s, i, 1)) + 1
Next i

For i = 0 To 9
sort_digits = sort_digits & String(a(i), Chr(Asc("0") + i))
Next i

End Function

HTH,
Bernd


toyota58

Digits in ascending order ?
 
Thank You so much...



All times are GMT +1. The time now is 01:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com