macro need quite complicated data sorting

leecavturbo

Well-known Member
Joined
Jan 4, 2008
Messages
681
here i have results from a race. the racers have numbers in the format of a20,c51 etc
then the name of the competitor and car make model.
then some times that they run. in the format of 11.80 secs the following times have either thousands or hundredthousths of a second which i only want to comma seperate the 2 decimals before and after so a 12.3456 will be ,12.34,ignoring the 56 then the next result and so on.
so i want to comma seperate the a20,andrewspeck,vauxhalltigra,11.27,13.36,12.87,12.91 etc etc
now the name and vehicle will cause huge sorting head ache so leave those together i can seperate them manually.
TIA
.
A7,Andrew Speck,Vauxhall Tigra,11.27,13.36116,12.87113,12.91124,12.14134,11.37129,11.27128
2A4Iain BurtVauxhall Astra11.8012.1011311.8811411.8211511.80120
A2Chris SuttonVauxhall Corsa11.9514.1911413.8811212.4612412.1511511.9511814.08112
A17Andy NichollsRover 200 Turbo12.0812.0811612.8211712.50119
1A4Iain BurtVauxhall Astra12.0812.0811212.5812312.4611612.5311712.2910512.18111
A4Iain BurtVauxhall Astra12.1313.5811512.6111712.1811012.4811512.1311112.29113
1A8Gareth BirchVauxhall Nova12.1412.1411612.769912.18119
A8Gareth BirchVauxhall Nova12.1912.9811412.3811012.4111513.009612.4611212.19114
1A7Andrew SpeckVauxhall Tigra12.2612.26131
A10Errol HuellHonda CRX Turbo12.3613.3211513.2912315.726912.3610822.3652
1A14Westan FrickerFiat Coupe Turbo12.7812.78110
A14Westan FrickerFiat Coupe Turbo12.8414.8411513.7411413.4011513.3011513.0511312.84109
A19Richard CooperRER Seat Ibiza12.9814.1711915.4510813.9710813.7111014.4010512.98119
A18Paul BargateVW Scirroco13.0613.5810437.128824.012313.06103
1A13Leighton WilsonFiat Coupe Turbo13.1413.1411713.798513.4811413.17116
A13Leighton WilsonFiat Coupe Turbo13.1414.1911314.0711316.1410713.3211513.1411713.47115
A12Nigel OgramFiat Coupe Turbo13.1614.0111014.4411114.1010813.16116
A16Mark CallisterEurospec Mitsubishi FTO13.2415.7910313.2410613.389627.084214.679415.8276
1A1David WilkinsonVauxhall Corsa13.3513.35105
A15Richard BattyMitsubishi FTO13.3614.7410713.36129
1A16Mark CallisterEurospec Mitsubishi FTO13.4714.348914.1110413.4711014.16108
A1David WilkinsonVauxhall Corsa13.5013.5110213.7710513.5910513.5010513.6210613.68102
A11Nick JonesTD Toyota Starlet13.5614.899115.929313.56105
A3Gavin WorkerVauxhall Corsa13.6214.7210913.6211014.3011616.236813.71115
1A19Richard CooperRER Seat Ibiza13.8114.359913.81109
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Excel Workbook
ABCDEFGHIJ
1Class A - Front Wheel Drive
2A7Andrew SpeckVauxhallTigra11.2713.3611612.8711312.9112412.1413411.3712911.27128
3A7Andrew SpeckVauxhall Tigra11.2713.3612.8712.9112.1411.3711.27
totbNUMBERS
 
Upvote 0
leecavturbo,

I can get the numbers, but ther is no logical pattern to the strings, from columns B thru D.

Before the macro:


Excel Workbook
ABCDEFGHIJK
1Class A - Front Wheel Drive
2A7Andrew SpeckVauxhallTigra11.2713.3611612.8711312.9112412.1413411.3712911.27128A7Andrew SpeckVauxhall Tigra11.2713.3612.8712.9112.1411.3711.27
3A7Andrew SpeckVauxhallTigra11.2713.3611612.8711312.9112412.1413411.3712911.27128
42A4Iain BurtVauxhall Astra11.8012.1011311.8811411.8211511.80120
5A2Chris SuttonVauxhall Corsa11.9514.1911413.8811212.4612412.1511511.9511814.08112
6A17Andy NichollsRover 200 Turbo12.0812.0811612.8211712.50119
71A4Iain BurtVauxhall Astra12.0812.0811212.5812312.4611612.5311712.2910512.18111
8A4Iain BurtVauxhall Astra12.1313.5811512.6111712.1811012.4811512.1311112.29113
91A8Gareth BirchVauxhall Nova12.1412.1411612.769912.18119
10A8Gareth BirchVauxhall Nova12.1912.9811412.3811012.4111513.009612.4611212.19114
111A7Andrew SpeckVauxhall Tigra12.2612.26131
12A10Errol HuellHonda CRX Turbo12.3613.3211513.2912315.726912.3610822.3652
131A14Westan FrickerFiat Coupe Turbo12.7812.78110
14A14Westan FrickerFiat Coupe Turbo12.8414.8411513.7411413.4011513.3011513.0511312.84109
15A19Richard CooperRER Seat Ibiza12.9814.1711915.4510813.9710813.7111014.4010512.98119
16A18Paul BargateVW Scirroco13.0613.5810437.128824.012313.06103
171A13Leighton WilsonFiat Coupe Turbo13.1413.1411713.798513.4811413.17116
18A13Leighton WilsonFiat Coupe Turbo13.1414.1911314.0711316.1410713.3211513.1411713.47115
19A12Nigel OgramFiat Coupe Turbo13.1614.0111014.4411114.1010813.16116
20A16Mark CallisterEurospec Mitsubishi FTO13.2415.7910313.2410613.389627.084214.679415.8276
211A1David WilkinsonVauxhall Corsa13.3513.35105
22A15Richard BattyMitsubishi FTO13.3614.7410713.36129
231A16Mark CallisterEurospec Mitsubishi FTO13.4714.348914.1110413.4711014.16108
24A1David WilkinsonVauxhall Corsa13.5013.5110213.7710513.5910513.5010513.6210613.68102
25A11Nick JonesTD Toyota Starlet13.5614.899115.929313.56105
26A3Gavin WorkerVauxhall Corsa13.6214.7210913.6211014.3011616.236813.71115
271A19Richard CooperRER Seat Ibiza13.8114.359913.81109
28
totbNUMBERS



After the macro:


Excel Workbook
ABCDEFGHIJK
1Class A - Front Wheel Drive
2A7Andrew SpeckVauxhallTigra11.2713.3611612.8711312.9112412.1413411.3712911.27128A7Andrew SpeckVauxhall Tigra11.2713.3612.8712.9112.1411.3711.27
3A7Andrew SpeckVauxhallTigra11.2713.3611612.8711312.9112412.1413411.3712911.2712811.2713.3612.8712.9112.1411.3711.27
42A4Iain BurtVauxhall Astra11.8012.1011311.8811411.8211511.8012011.8012.1011.8811.8211.80
5A2Chris SuttonVauxhall Corsa11.9514.1911413.8811212.4612412.1511511.9511814.0811211.9514.1913.8812.4612.1511.9514.08
6A17Andy NichollsRover 200 Turbo12.0812.0811612.8211712.5011912.0812.0812.8212.50
71A4Iain BurtVauxhall Astra12.0812.0811212.5812312.4611612.5311712.2910512.1811112.0812.0812.5812.4612.5312.2912.18
8A4Iain BurtVauxhall Astra12.1313.5811512.6111712.1811012.4811512.1311112.2911312.1313.5812.6112.1812.4812.1312.29
91A8Gareth BirchVauxhall Nova12.1412.1411612.769912.1811912.1412.1412.7612.18
10A8Gareth BirchVauxhall Nova12.1912.9811412.3811012.4111513.009612.4611212.1911412.1912.9812.3812.4113.0012.4612.19
111A7Andrew SpeckVauxhall Tigra12.2612.2613112.2612.26
12A10Errol HuellHonda CRX Turbo12.3613.3211513.2912315.726912.3610822.365212.3613.3213.2915.7212.3622.36
131A14Westan FrickerFiat Coupe Turbo12.7812.7811012.7812.78
14A14Westan FrickerFiat Coupe Turbo12.8414.8411513.7411413.4011513.3011513.0511312.8410912.8414.8413.7413.4013.3013.0512.84
15A19Richard CooperRER Seat Ibiza12.9814.1711915.4510813.9710813.7111014.4010512.9811912.9814.1715.4513.9713.7114.4012.98
16A18Paul BargateVW Scirroco13.0613.5810437.128824.012313.0610313.0613.5837.1224.0113.06
171A13Leighton WilsonFiat Coupe Turbo13.1413.1411713.798513.4811413.1711613.1413.1413.7913.4813.17
18A13Leighton WilsonFiat Coupe Turbo13.1414.1911314.0711316.1410713.3211513.1411713.4711513.1414.1914.0716.1413.3213.1413.47
19A12Nigel OgramFiat Coupe Turbo13.1614.0111014.4411114.1010813.1611613.1614.0114.4414.1013.16
20A16Mark CallisterEurospec Mitsubishi FTO13.2415.7910313.2410613.389627.084214.679415.827613.2415.7913.2413.3827.0814.6715.82
211A1David WilkinsonVauxhall Corsa13.3513.3510513.3513.35
22A15Richard BattyMitsubishi FTO13.3614.7410713.3612913.3614.7413.36
231A16Mark CallisterEurospec Mitsubishi FTO13.4714.348914.1110413.4711014.1610813.4714.3414.1113.4714.16
24A1David WilkinsonVauxhall Corsa13.5013.5110213.7710513.5910513.5010513.6210613.6810213.5013.5113.7713.5913.5013.6213.68
25A11Nick JonesTD Toyota Starlet13.5614.899115.929313.5610513.5614.8915.9213.56
26A3Gavin WorkerVauxhall Corsa13.6214.7210913.6211014.3011616.236813.7111513.6214.7213.6214.3016.2313.71
271A19Richard CooperRER Seat Ibiza13.8114.359913.8110913.8114.3513.81
28
totbNUMBERS




Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Adding the Macro
1. Copy the below macro, by highlighting the macro code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT+F11 to open the Visual Basic Editor
4. Press the keys ALT+I to activate the Insert menu
5. Press M to insert a Standard Module
6. Paste the code by pressing the keys CTRL + V
7. Press the keys ALT+Q to exit the Editor, and return to Excel

Code:
Option Explicit
Sub SplitData()
Dim c As Range, a As Long, b As Long, LR As Long, LUC As Long
Dim Sp
Application.ScreenUpdating = False
For Each c In Range("A3", Range("A" & Rows.Count).End(xlUp))
  Sp = Split(c.Value, ".")
  b = UBound(Sp) - 1
  For a = LBound(Sp) To b
    Cells(c.Row, a + 5) = Right(Sp(a), 2) & "." & Left(Sp(a + 1), 2)
  Next a
Next c
LR = Cells(Rows.Count, 1).End(xlUp).Row
LUC = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
Range(Cells(3, 5), Cells(LR, LUC)).NumberFormat = "0.00"
Application.ScreenUpdating = True
End Sub


Then run the "SplitData" macro.
 
Last edited:
Upvote 0
leecavturbo,

Before the new macro:


Excel Workbook
ABCDEFGHIJK
1Class A - Front Wheel Drive
2A7Andrew SpeckVauxhallTigra11.2713.3611612.8711312.9112412.1413411.3712911.27128
32A4Iain BurtVauxhall Astra11.8012.1011311.8811411.8211511.80120
4A2Chris SuttonVauxhall Corsa11.9514.1911413.8811212.4612412.1511511.9511814.08112
5A17Andy NichollsRover 200 Turbo12.0812.0811612.8211712.50119
61A4Iain BurtVauxhall Astra12.0812.0811212.5812312.4611612.5311712.2910512.18111
7A4Iain BurtVauxhall Astra12.1313.5811512.6111712.1811012.4811512.1311112.29113
81A8Gareth BirchVauxhall Nova12.1412.1411612.769912.18119
9A8Gareth BirchVauxhall Nova12.1912.9811412.3811012.4111513.009612.4611212.19114
101A7Andrew SpeckVauxhall Tigra12.2612.26131
11A10Errol HuellHonda CRX Turbo12.3613.3211513.2912315.726912.3610822.3652
121A14Westan FrickerFiat Coupe Turbo12.7812.78110
13A14Westan FrickerFiat Coupe Turbo12.8414.8411513.7411413.4011513.3011513.0511312.84109
14A19Richard CooperRER Seat Ibiza12.9814.1711915.4510813.9710813.7111014.4010512.98119
15A18Paul BargateVW Scirroco13.0613.5810437.128824.012313.06103
161A13Leighton WilsonFiat Coupe Turbo13.1413.1411713.798513.4811413.17116
17A13Leighton WilsonFiat Coupe Turbo13.1414.1911314.0711316.1410713.3211513.1411713.47115
18A12Nigel OgramFiat Coupe Turbo13.1614.0111014.4411114.1010813.16116
19A16Mark CallisterEurospec Mitsubishi FTO13.2415.7910313.2410613.389627.084214.679415.8276
201A1David WilkinsonVauxhall Corsa13.3513.35105
21A15Richard BattyMitsubishi FTO13.3614.7410713.36129
221A16Mark CallisterEurospec Mitsubishi FTO13.4714.348914.1110413.4711014.16108
23A1David WilkinsonVauxhall Corsa13.5013.5110213.7710513.5910513.5010513.6210613.68102
24A11Nick JonesTD Toyota Starlet13.5614.899115.929313.56105
25A3Gavin WorkerVauxhall Corsa13.6214.7210913.6211014.3011616.236813.71115
261A19Richard CooperRER Seat Ibiza13.8114.359913.81109
27
totbNUMBERS



[/b]After the new macro:[/b]


Excel Workbook
ABCDEFGHIJK
1Class A - Front Wheel Drive
2A7Andrew SpeckVauxhallTigra11.2713.3611612.8711312.9112412.1413411.3712911.27128A7Andrew SpeckVauxhallTigra11.2713.3612.8712.9112.1411.3711.27
32A4Iain BurtVauxhall Astra11.8012.1011311.8811411.8211511.801202A4Iain BurtVauxhall Astra11.8012.1011.8811.8211.80
4A2Chris SuttonVauxhall Corsa11.9514.1911413.8811212.4612412.1511511.9511814.08112A2Chris SuttonVauxhall Corsa11.9514.1913.8812.4612.1511.9514.08
5A17Andy NichollsRover 200 Turbo12.0812.0811612.8211712.50119A17Andy NichollsRover 200 Turbo12.0812.0812.8212.50
61A4Iain BurtVauxhall Astra12.0812.0811212.5812312.4611612.5311712.2910512.181111A4Iain BurtVauxhall Astra12.0812.0812.5812.4612.5312.2912.18
7A4Iain BurtVauxhall Astra12.1313.5811512.6111712.1811012.4811512.1311112.29113A4Iain BurtVauxhall Astra12.1313.5812.6112.1812.4812.1312.29
81A8Gareth BirchVauxhall Nova12.1412.1411612.769912.181191A8Gareth BirchVauxhall Nova12.1412.1412.7612.18
9A8Gareth BirchVauxhall Nova12.1912.9811412.3811012.4111513.009612.4611212.19114A8Gareth BirchVauxhall Nova12.1912.9812.3812.4113.0012.4612.19
101A7Andrew SpeckVauxhall Tigra12.2612.261311A7Andrew SpeckVauxhall Tigra12.2612.26
11A10Errol HuellHonda CRX Turbo12.3613.3211513.2912315.726912.3610822.3652A10Errol HuellHonda CRX Turbo12.3613.3213.2915.7212.3622.36
121A14Westan FrickerFiat Coupe Turbo12.7812.781101A14Westan FrickerFiat Coupe Turbo12.7812.78
13A14Westan FrickerFiat Coupe Turbo12.8414.8411513.7411413.4011513.3011513.0511312.84109A14Westan FrickerFiat Coupe Turbo12.8414.8413.7413.4013.3013.0512.84
14A19Richard CooperRER Seat Ibiza12.9814.1711915.4510813.9710813.7111014.4010512.98119A19Richard CooperRER Seat Ibiza12.9814.1715.4513.9713.7114.4012.98
15A18Paul BargateVW Scirroco13.0613.5810437.128824.012313.06103A18Paul BargateVW Scirroco13.0613.5837.1224.0113.06
161A13Leighton WilsonFiat Coupe Turbo13.1413.1411713.798513.4811413.171161A13Leighton WilsonFiat Coupe Turbo13.1413.1413.7913.4813.17
17A13Leighton WilsonFiat Coupe Turbo13.1414.1911314.0711316.1410713.3211513.1411713.47115A13Leighton WilsonFiat Coupe Turbo13.1414.1914.0716.1413.3213.1413.47
18A12Nigel OgramFiat Coupe Turbo13.1614.0111014.4411114.1010813.16116A12Nigel OgramFiat Coupe Turbo13.1614.0114.4414.1013.16
19A16Mark CallisterEurospec Mitsubishi FTO13.2415.7910313.2410613.389627.084214.679415.8276A16Mark CallisterEurospec Mitsubishi FTO13.2415.7913.2413.3827.0814.6715.82
201A1David WilkinsonVauxhall Corsa13.3513.351051A1David WilkinsonVauxhall Corsa13.3513.35
21A15Richard BattyMitsubishi FTO13.3614.7410713.36129A15Richard BattyMitsubishi FTO13.3614.7413.36
221A16Mark CallisterEurospec Mitsubishi FTO13.4714.348914.1110413.4711014.161081A16Mark CallisterEurospec Mitsubishi FTO13.4714.3414.1113.4714.16
23A1David WilkinsonVauxhall Corsa13.5013.5110213.7710513.5910513.5010513.6210613.68102A1David WilkinsonVauxhall Corsa13.5013.5113.7713.5913.5013.6213.68
24A11Nick JonesTD Toyota Starlet13.5614.899115.929313.56105A11Nick JonesTD Toyota Starlet13.5614.8915.9213.56
25A3Gavin WorkerVauxhall Corsa13.6214.7210913.6211014.3011616.236813.71115A3Gavin WorkerVauxhall Corsa13.6214.7213.6214.3016.2313.71
261A19Richard CooperRER Seat Ibiza13.8114.359913.811091A19Richard CooperRER Seat Ibiza13.8114.3513.81
27
totbNUMBERS



Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Adding the Macro
1. Copy the below macro, by highlighting the macro code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT+F11 to open the Visual Basic Editor
4. Press the keys ALT+I to activate the Insert menu
5. Press M to insert a Standard Module
6. Paste the code by pressing the keys CTRL + V
7. Press the keys ALT+Q to exit the Editor, and return to Excel

Code:
Option Explicit
Sub SplitData()
Dim c As Range, a As Long, b As Long, MyU As Long, LR As Long, LUC As Long
Dim Sp
Dim Hold As String
Application.ScreenUpdating = False
For Each c In Range("A2", Range("A" & Rows.Count).End(xlUp))
  Sp = Split(c.Value, ".")
  Hold = Left(Sp(0), Len(Sp(0)) - 2)
  MyU = 0
  For b = 1 To Len(Hold) Step 1
    Select Case Mid(Hold, b, 1)
      Case Is = "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
        MyU = MyU + 1
        If MyU = 2 Then
          Cells(c.Row, 2) = Left(Hold, b - 1)
          Hold = Right(Hold, Len(Hold) - b + 1)
          Exit For
        End If
    End Select
  Next b
  MyU = 0
  For b = 1 To Len(Hold) Step 1
    Select Case Mid(Hold, b, 1)
      Case Is = "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
        MyU = MyU + 1
        If MyU = 3 Then
          Cells(c.Row, 3) = Left(Hold, b - 1)
          Hold = Right(Hold, Len(Hold) - b + 1)
          Cells(c.Row, 4) = Hold
          Exit For
        End If
    End Select
  Next b
  b = UBound(Sp) - 1
  For a = LBound(Sp) To b
    Cells(c.Row, a + 5) = Right(Sp(a), 2) & "." & Left(Sp(a + 1), 2)
  Next a
Next c
LR = Cells(Rows.Count, 1).End(xlUp).Row
LUC = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
Range(Cells(3, 5), Cells(LR, LUC)).NumberFormat = "0.00"
Application.ScreenUpdating = True
End Sub


Then run the new "SplitData" macro.
 
Upvote 0
leecavturbo,

Slight update to the code.

Code:
Option Explicit
Sub SplitData()
Dim c As Range, a As Long, b As Long, MyU As Long, LR As Long, LUC As Long
Dim Sp
Dim Hold As String
Application.ScreenUpdating = False
For Each c In Range("A2", Range("A" & Rows.Count).End(xlUp))
  Sp = Split(c.Value, ".")
  Hold = Left(Sp(0), Len(Sp(0)) - 2)
  MyU = 0
  For b = 1 To Len(Hold) Step 1
    Select Case Mid(Hold, b, 1)
      Case "A" To "Z"
        MyU = MyU + 1
        If MyU = 2 Then
          Cells(c.Row, 2) = Left(Hold, b - 1)
          Hold = Right(Hold, Len(Hold) - b + 1)
          Exit For
        End If
    End Select
  Next b
  MyU = 0
  For b = 1 To Len(Hold) Step 1
    Select Case Mid(Hold, b, 1)
      Case "A" To "Z"
        MyU = MyU + 1
        If MyU = 3 Then
          Cells(c.Row, 3) = Left(Hold, b - 1)
          Hold = Right(Hold, Len(Hold) - b + 1)
          Cells(c.Row, 4) = Hold
          Exit For
        End If
    End Select
  Next b
  b = UBound(Sp) - 1
  For a = LBound(Sp) To b
    Cells(c.Row, a + 5) = Right(Sp(a), 2) & "." & Left(Sp(a + 1), 2)
  Next a
Next c
LR = Cells(Rows.Count, 1).End(xlUp).Row
Application.Volatile
LUC = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
Range(Cells(3, 5), Cells(LR, LUC)).NumberFormat = "0.00"
Application.ScreenUpdating = True
End Sub
 
Upvote 0
thx hiker. i knew it would be quite difficult in trying to make a code that looked for the change from letters to numbers and then even 2 numbers before a decimel point then 2 after and ignoring any in between.
good effort
thx
1 point hiker. the data i gave in the example was just a short version there are many many more rows if that makes a difference to the code as i tried to run it and got a out of range error!?
 
Last edited:
Upvote 0
debug.jpg
 
Upvote 0

Forum statistics

Threads
1,221,575
Messages
6,160,603
Members
451,657
Latest member
Ang24

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