Sort string

Temporary-Failure

Board Regular
Joined
Jul 16, 2010
Messages
140
I have string in cell A1: 4x100 5x98 4x108 4x98 4x114,3 5x120 3x112. My job is to sort this string to be as 3x112 4x98 4x100 4x108 4x114,3 5x98 5x120. These are car pdc's. First has to be 3 bolt, then 4 bolt and last 5 bolt. Then circle has to be from lowest to highest. I cannot find solution.
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I have string in cell A1: 4x100 5x98 4x108 4x98 4x114,3 5x120 3x112. My job is to sort this string to be as 3x112 4x98 4x100 4x108 4x114,3 5x98 5x120. These are car pdc's. First has to be 3 bolt, then 4 bolt and last 5 bolt. Then circle has to be from lowest to highest. I cannot find solution.
4x100 5x98 4x108 4x98 4x114 5x120 3x1124x1005x98 4x108 4x98 4x114 5x120 3x1125x984x108 4x98 4x114 5x120 3x1124x1084x98 4x114 5x120 3x1124x984x114 5x120 3x1124x1145x120 3x1125x1203x112#VALUE!#VALUE!#VALUE!#VALUE!#VALUE!
4x10041004.0000015100
5x985985.000001698
4x10841084.0000017108
4x984984.000001898
4x11441144.0000019114
5x12051205.000002120
3x11231123.0000021112
#VALUE!#VALUE!#VALUE!
#VALUE!#VALUE!#VALUE!
after clunk clunk clunk here you are !!!
13.00000211123x112
24.00000151004x100
34.00000171084x108
44.0000018984x98
54.00000191144x114
65.0000016985x98
75.0000021205x120
8
9
10

<colgroup><col><col><col><col><col><col><col><col><col><col><col><col><col><col span="7"></colgroup><tbody>
</tbody>
 
Upvote 0
Try this:-
Data in "A1" , Results in "F1"
Code:
[COLOR="Navy"]Sub[/COLOR] MG07Nov08
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Sp [COLOR="Navy"]As[/COLOR] Variant, K [COLOR="Navy"]As[/COLOR] Variant, Q [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Dim[/COLOR] Srt [COLOR="Navy"]As[/COLOR] Object, Ray [COLOR="Navy"]As[/COLOR] Variant

[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
txt = Replace(Range("A1"), ",", ".")

[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Sp [COLOR="Navy"]In[/COLOR] Split(txt, " ")
    [COLOR="Navy"]If[/COLOR] Not .Exists(Split(Sp, "x")(0)) [COLOR="Navy"]Then[/COLOR]
        ReDim Ray(0)
        Ray(0) = Split(Sp, "x")(1)
        .Add Split(Sp, "x")(0), Ray
    [COLOR="Navy"]Else[/COLOR]
       Q = .Item(Split(Sp, "x")(0))
            ReDim Preserve Q(UBound(Q) + 1)
            Q(UBound(Q)) = Split(Sp, "x")(1)
      .Item(Split(Sp, "x")(0)) = Q
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]

[COLOR="Navy"]Dim[/COLOR] r [COLOR="Navy"]As[/COLOR] Variant, nStr [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] St [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] Srt1 [COLOR="Navy"]As[/COLOR] Variant


[COLOR="Navy"]Set[/COLOR] Srt1 = CreateObject("System.Collections.ArrayList")
    [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] r [COLOR="Navy"]In[/COLOR] .keys()
        Srt1.Add r
    [COLOR="Navy"]Next[/COLOR] r
    Srt1.Sort
    Ray = Srt1.toarray

    [COLOR="Navy"]For[/COLOR] n = 0 To UBound(Ray)
        [COLOR="Navy"]Set[/COLOR] Srt = CreateObject("System.Collections.ArrayList")
        [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] r [COLOR="Navy"]In[/COLOR] .Item(Ray(n))
            Srt.Add Val(r)
        [COLOR="Navy"]Next[/COLOR] r
        Srt.Sort

        [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] r [COLOR="Navy"]In[/COLOR] Srt.toarray
            nStr = nStr & IIf(nStr = "", Ray(n) & "x" & r, " " & Ray(n) & "x" & r)
        [COLOR="Navy"]Next[/COLOR] r
        St = St & IIf(St = "", nStr, " " & nStr)
        nStr = ""
    [COLOR="Navy"]Next[/COLOR] n
Range("F1") = Replace(St, ".", ",")
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top