An LP member posted these a number of years ago:
You will need to save your Excel file as a macro (.xlsm)
Macros will require you to changed the security settings in Excel
Google macro security that pertains to your version of Excel
Pick 3
Using the example cell J8
formula =lowform_3(J8)
Function lowform_3(three_digit)
Dim channel() As Integer
Dim slot() As Integer
Dim num As Integer, pos As Integer
Dim c0, c1, c2, c3
c0 = three_digit
c1 = Int(c0 / 100)
c2 = Int((c0 Mod 100) / 10)
c3 = c0 Mod 10
ReDim channel(9)
ReDim slot(3)
channel(c1) = channel(c1) + 1
channel(c2) = channel(c2) + 1
channel(c3) = channel(c3) + 1
pos = 1
For num = 0 To 9
While channel(num) > 0
slot(pos) = num
channel(num) = channel(num) - 1
pos = pos + 1
Wend
Next num
lowform_3 = slot(1) * 100 + slot(2) * 10 + slot(3)
End Function
Pick 4:
Formula
=lowform_4(J8)
Function lowform_4(four_digit)
Dim channel() As Integer
Dim slot() As Integer
Dim num As Integer, pos As Integer
Dim c0, c1, c2, c3, c4
c0 = four_digit
c1 = Int(c0 / 1000)
c2 = Int((c0 Mod 1000) / 100)
c3 = Int((c0 Mod 100) / 10)
c4 = c0 Mod 10
ReDim channel(9)
ReDim slot(4)
channel(c1) = channel(c1) + 1
channel(c2) = channel(c2) + 1
channel(c3) = channel(c3) + 1
channel(c4) = channel(c4) + 1
pos = 1
For num = 0 To 9
While channel(num) > 0
slot(pos) = num
channel(num) = channel(num) - 1
pos = pos + 1
Wend
Next num
lowform_4 = slot(1) * 1000 + slot(2) * 100 + slot(3) * 10 + slot(4)
End Function