Extract Text After Space In String

holmbjerg

New Member
Joined
Jul 7, 2011
Messages
6
I need to extract text after space in string e.g.

INV1019469 Intrum Justitia Oy
INV1028 Petskiboat Oy
INV102812 Palo, Tolvanen & Al
INV103 Fast Capital Oy

Result:
Intrum Justitia Oy
Petskiboat Oy
Palo, Tolvanen & Al
Fast Capital Oy

Thanks
Lasse
 
Last edited:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Instr function is your friend for this:

InStr returns the position of the first occurance of a string inside another string

so:

Code:
Instr("INV1019469 Intrum Justitia Oy", " ")

will return 11

you can nest this inside another function or assign it as a variable

Code:
dim fooStr as string
dim cutDownStr
 
cutDownStr = "INV1019469 Intrum Justitia Oy"
 
fooStr = right(cutDownStr, (len(cutDownStr)-inStr(cutDownStr, " "))

Len finds the lenght of the string and Right takes the right part of the string up to the number of characters in the second argument
 
Upvote 0
UDF
Code:
[COLOR="Blue"]Function[/COLOR] ExtractText(Str [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]String[/COLOR]) [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]String[/COLOR]
    [COLOR="Blue"]With[/COLOR] CreateObject("VBScript.RegExp")
        .Pattern = "\b(?!\w*\d+)([A-Za-z]+\s*)+"
        ExtractText = .Execute(Str)(0)
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Function[/COLOR]
 
Upvote 0
With ZPhantom's example, also:

Code:
Dim fooStr As String
Dim cutDownStr
 
cutDownStr = "INV1019469 Intrum Justitia Oy"
fooStr = Mid(cutDownStr, 1 + InStr(cutDownStr, " "))
 
Upvote 0
Adjusted to examples:
Code:
[COLOR="Blue"]Function[/COLOR] ExtractText(Str [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]String[/COLOR]) [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]String[/COLOR]
    [COLOR="Blue"]With[/COLOR] CreateObject("VBScript.RegExp")
        .Pattern = "\b(?!\w*\d+).+"
        ExtractText = Trim(.Execute(Str)(0))
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Function[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,383
Members
448,955
Latest member
BatCoder

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