Hmmmmmmmmmmmm,
Some 'issues' here?
Quan9r, If you use the second two digits in a string sort, the order will be different than a numeric sort of the same, so YOU need to know which sort order you want.
Maquis , NO. Please re-read the post. By "... sort by the last two numbers ... " Quan9r is clearly meaning to sort by the RIGHT pair of digits, with a sub-sort on the left pair of digits. Further, you never explained HOW to do the double sort, just told him to "do it".
blavuma, see comment to Quan
I do not think I have 'all the facts' for this, especially wheather the 'sort' should be numeric or string based, but also wheather the item list is a recordset or just some collection generated dynamically or from 'elsewhere' and just used.
The first option which occurs to me is to generate a companion value with the pair of 'digits; swapped', and then sort on that companion, but again, the issues noted above (esp. the alpha-Numeric) have an impact on this implementation.
The simple procedure will do the swapping - wit the option for a numeric or string value. Without more details of the source / destination of the process, attempting to provide the actual sort mechanics is more than I care to take on, and it is probably within Quan9r's capability anyway.
Code:
Public Function SwapDigPairs(ByVal intFourNum As Variant, Optional blnAnFlg = False) As Variant
'Swaps the digit pairs of a four digit Number
'Usage
'(Numeric Return; w/o Flag)
'? SwapDigPairs(1201)
' 112
'(Alpha Return; w/Flag)
'? SwapDigPairs(1201, True)
'0112
Dim tmpLftPr As Integer
Dim tmpRgtPr As Integer
tmpLftPr = intFourNum \ 100
tmpRgtPr = intFourNum - 100 * tmpLftPr
If (blnAnFlg = True) Then
SwapDigPairs = Format(CStr(tmpRgtPr), "00") & Format(CStr(tmpLftPr), "00")
Else
SwapDigPairs = tmpRgtPr * 100 + tmpLftPr
End If
End Function
MichaelRed
m.red@att.net
There is never time to do it right but there is always time to do it over