Split multiple groups of numbers with decimal points from a string

SamJoy

New Member
Joined
Sep 4, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello Friends

I need help splitting a cell containing text, multiple groups of numbers, and decimal places.
e.g. if cell contains S = " Dagen gewerkt 21,00 195,00"
I need to separate the text part into one column, then 21.00 into another column, and 195.00 into another cell

I have multiple such columns to deal with.
Any help in this regard is highly appriciated.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Natural solution in such situation would be by using RegEx (Regular Expressions).
Members of Insider program do have already access to such functions.
Unfortunately, standard Microsoft 365 users - not yet.

But we can use UDF (user defined Function) in VBA, and use it as normal function in the worksheet.
A code for such function (original source: General Purpose UDFs for using Regular Expressions in Excel ) could look like that:
VBA Code:
Public Function RXMatches(Text As String, Pattern As String, Optional Group As Integer = 0, Optional IgnoreCase As Boolean = True) As Variant
    Dim retval() As String, i As Long
    ' from 
    
    ' Takes a string and returns all matches in a vertical array
    ' Text is the string to be searched
    ' Pattern is the regex pattern
    ' Group (optional) selects a parenthesized group (count the number of left parentheses preceding it to get the group number)
    ' IgnoreCase (optional) set to False for a case-sensitive search

    Dim RE As Object
    Dim Matches As Object

    Set RE = CreateObject("vbscript.regexp")
    RE.IgnoreCase = IgnoreCase
    RE.Global = True
    RE.Pattern = Pattern

    Set Matches = RE.Execute(Text)

    If (Matches.Count > 0) Then
        ReDim retval(0 To Matches.Count - 1)
        For i = 0 To Matches.Count - 1
            If (Group > 0) Then
                retval(i) = Matches(i).submatches(Group - 1)
            Else
                retval(i) = Matches(i)
            End If
        Next i
    Else
        ReDim retval(1)
        retval(0) = ""
    End If

    RXMatches = Application.Transpose(retval)
End Function

And the use in the worksheet would be:
=TRANSPOSE(RXMatches(A2,"([\D]+\s|\d*,\d*)"))

This string: "([\D]+\s|\d*,\d*)" defines a pattern for searching. If you want to have it explained - write it (without quotation marks) in "formula bar" on regex101: build, test, and debug regex and sample of your text in the window below
 

Attachments

  • Zrzut ekranu 2024-09-04 193804.png
    Zrzut ekranu 2024-09-04 193804.png
    25.3 KB · Views: 3
  • Zrzut ekranu 2024-09-04 194042.png
    Zrzut ekranu 2024-09-04 194042.png
    155 KB · Views: 3
Upvote 0
Hello, the example could probably be addressed via e.g. something like this:

Excel Formula:
=LET(
a,A1,
s,TEXTSPLIT(a," "),
t,ISNUMBER(--(s)),
HSTACK(TEXTJOIN(" ",,FILTER(s,t=FALSE)),--(FILTER(s,t=TRUE))))

But could you please upload a sample of the data because there may be more possible arrangements...
 
Upvote 0
With irregular names (containing spaces) and then numbers separeted by spaces TextToColumns tool will probably by not-so-easy to setup. Unfortunately, we got just one sample row of input data :-(
 
Upvote 0
With Dagen gewerkt 21,00 195,00 in A1
B1: =TRIM(LEFT(A1,MIN(IFERROR(FIND(SEQUENCE(10,,0),A1),""))-1))
C1: =TEXTSPLIT(TEXTAFTER(A1,B1)," ",,TRUE)
 
Upvote 0
Natural solution in such situation would be by using RegEx (Regular Expressions).
Members of Insider program do have already access to such functions.
Unfortunately, standard Microsoft 365 users - not yet.

But we can use UDF (user defined Function) in VBA, and use it as normal function in the worksheet.
A code for such function (original source: General Purpose UDFs for using Regular Expressions in Excel ) could look like that:
VBA Code:
Public Function RXMatches(Text As String, Pattern As String, Optional Group As Integer = 0, Optional IgnoreCase As Boolean = True) As Variant
    Dim retval() As String, i As Long
    ' from
  
    ' Takes a string and returns all matches in a vertical array
    ' Text is the string to be searched
    ' Pattern is the regex pattern
    ' Group (optional) selects a parenthesized group (count the number of left parentheses preceding it to get the group number)
    ' IgnoreCase (optional) set to False for a case-sensitive search

    Dim RE As Object
    Dim Matches As Object

    Set RE = CreateObject("vbscript.regexp")
    RE.IgnoreCase = IgnoreCase
    RE.Global = True
    RE.Pattern = Pattern

    Set Matches = RE.Execute(Text)

    If (Matches.Count > 0) Then
        ReDim retval(0 To Matches.Count - 1)
        For i = 0 To Matches.Count - 1
            If (Group > 0) Then
                retval(i) = Matches(i).submatches(Group - 1)
            Else
                retval(i) = Matches(i)
            End If
        Next i
    Else
        ReDim retval(1)
        retval(0) = ""
    End If

    RXMatches = Application.Transpose(retval)
End Function

And the use in the worksheet would be:
=TRANSPOSE(RXMatches(A2,"([\D]+\s|\d*,\d*)"))

This string: "([\D]+\s|\d*,\d*)" defines a pattern for searching. If you want to have it explained - write it (without quotation marks) in "formula bar" on regex101: build, test, and debug regex and sample of your text in the window below
Thank you so much for this. I will test this and update you. Once again Thank You :) Will try to play around this solution as i have many such columns with variations.
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,226
Members
452,620
Latest member
dsubash

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