Formula to extract numbers from text

Obewan

Board Regular
Joined
Aug 25, 2021
Messages
68
Office Version
  1. 365
Platform
  1. Windows
I have numbers that appear in the following format in column A. i want a formula in columns B:E that would separate them so probably 4 different fomrulas. The answer to the first row would be
B1 = 3
C1 = 2
D1= 0
E1 = 0

3: 2- 0- 0
21: 3- 3- 2
2: 1- 0- 0
2: 0- 2- 0
3: 1- 1- 0

Thanks in advance
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi & welcome to MrExcel.
How about
+Fluff 1.xlsm
ABCDE
1
23: 2- 0- 03200
321: 3- 3- 221332
42: 1- 0- 02100
52: 0- 2- 02020
63: 1- 1- 03110
Main
Cell Formulas
RangeFormula
B2:E6B2=TRANSPOSE(FILTERXML("<k><m>"&SUBSTITUTE(SUBSTITUTE(A2,":","</m><m>"),"-","</m><m>")&"</m></k>","//m"))
Dynamic array formulas.
 
Upvote 0
VBA >
VBA Code:
Sub test()
    Dim i&, ii&
    [B:E].ClearContents
    With CreateObject("Vbscript.Regexp")
        .Pattern = "(\d+)\:\s(\d+)\-\s(\d+)\-\s(\d+)"
        For i = 1 To Cells(Rows.Count, 1).End(3).Row
            If .test(Cells(i, 1).Value) Then
                With .Execute(Cells(i, 1).Value)(0).submatches
                    For ii = 0 To .Count - 1
                        Cells(i, ii + 2).Value = .Item(ii)
                    Next ii
                End With
            End If
        Next i
    End With
End Sub
VBA Code:
Sub test2()
    Dim i&
    [B:E].ClearContents
    For i = 1 To Cells(Rows.Count, 1).End(3).Row
        Cells(i, 2).Resize(, 4).Value = Split(Replace(Cells(i, 1).Value, ":", "-"), "- ")
    Next i
End Sub
 
Upvote 0
Here is another formula solution you can consider (put it in cell B2 and copy across to E2, then copy B2:E2 down)
Excel Formula:
=TRIM(MID(SUBSTITUTE(" "&SUBSTITUTE(SUBSTITUTE($A2,"-",""),":","")," ",REPT(" ",99)),COLUMNS($B:B)*99,99))
And here is another macro that you can also consider...
VBA Code:
Sub SplitOutNumbers()
  Dim Cell As Range
  Application.ScreenUpdating = False
  For Each Cell In Range("A2", Cells(Rows.Count, "A").End(xlUp))
     With Cell.Offset(, 1).Resize(, 4)
       .Cells = Split(Replace(Replace(Cell.Value, ":", ""), "-", ""))
       .Value = .Value
     End With
  Next
  Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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