Formula to Parse numeric text in single field into multiple columns - Excel

I have a field coming from a database that contains a string of data like so:

I need to split this into three different columns but only the numeric value
Col1             Col2            Col3
1                     4                  5
4                     3                  8

I have tried about 10 different approaches and am getting results, just not usable results.

Any advise would be appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

if field is always the same format you can do

Each one in diff cell
byundtMechanical EngineerCommented:
I wrote a user-defined function (UDF) to split your text and return the numeric values. You use store the UDF in a regular module sheet (just like a macro). As written, the UDF doesn't care how many segments there are coming over from the database. Nor does it care how many letter precede the numbers, or how many digits there are in each number.

Below the code, I show two different ways of using the UDF in worksheet formulas. The sample workbook attached to this Comment shows those formulas in action.
Function SplitNumbers(sText As String, sDelimiter As String) As Variant
Dim v As Variant, vResults As Variant, vSplit As Variant
Dim s As String
Dim i As Long
vSplit = Split(sText, sDelimiter)
ReDim vResults(0 To UBound(vSplit))
For Each v In vSplit
    s = StrReverse(v)
    vResults(i) = Val(StrReverse(Val(s) & ""))
    i = i + 1
SplitNumbers = vResults
End Function

Open in new window

If you want to return all three values at once, select three cells in a row, then array-enter a formula like:

If you want to return the values individually, copy across a formula like:
byundtMechanical EngineerCommented:
If you really want a formula only solution, I suggest the following:
1. Use the Data...Text to Columns method with a colon as the delimiter to split your data into 3 columns.
2. Use a formula like shown below to extract the numeric portion out of up to a 5 character string in cell K1:

If you need more possible characters, then keep adding IFERROR blocks to the concatenation.

I've updated the sample workbook to show the formula method in action. I also included some formulas to split the text into three substrings.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Another UDF.
Assuming your string is in A1, then try this....
In B1
and then copy across to three columns.

Pls refer to the attached for more details.
Function ExtractNumber(Str As Range, i As Long) As String
Dim RegEx As Object
Dim Match As Object
Set RegEx = CreateObject("vbscript.regexp")
With RegEx
   .IgnoreCase = True
   .Pattern = "\d"
   .Global = True
End With
If RegEx.test(Str) = True Then
   Set Match = RegEx.Execute(Str)
   ExtractNumber = Match(i - 1)
   ExtractNumber = ""
End If
End Function

Open in new window

byundtMechanical EngineerCommented:
I noticed that my UDF would truncate trailing zeros from the number returned. The formula only solution does not have such a problem.

The fix for the UDF (assuming your database text does not include any decimal points) is shown below. Leading zeros will still be truncated because the result is returned as numbers rather than text.
Function SplitNumbers(sText As String, sDelimiter As String) As Variant
Dim vResults As Variant, vSplit As Variant
Dim i As Long
vSplit = Split(sText, sDelimiter)
ReDim vResults(0 To UBound(vSplit))
For i = 0 To UBound(vSplit)
    vResults(i) = Val(StrReverse(CStr(Val("." & StrReverse(vSplit(i))))))
SplitNumbers = vResults
End Function

Open in new window

clintnashAuthor Commented:
Thank you for both options you provided. That one had stumped me...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.