Extract Word starting from first letter

nicnad

Board Regular
Joined
Sep 12, 2011
Messages
199
Hi,


I have cells that contains :

1234-5678-Barrack Obama
4567-7655-124678-Ben Bernanke


How do I extract the text string starting from the first letter? (i.e Barrack Obama, Ben Bernanke)

Thank you.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi

Assuming the name is always after the last hyphen, like in the examples, try:

=TRIM(RIGHT(SUBSTITUTE(A1,"-",REPT(" ",99)),99))
 
Upvote 0
Hey PGC
I was going to throw in my first Regex solution !!
 
Upvote 0
Not sure how give alphabets using RegExp on its own but used substitute formula with it. Is there a better way to give alphabets?

Still learning.

Sheet1


<TABLE style="BACKGROUND-COLOR: #ffffff; PADDING-LEFT: 2pt; PADDING-RIGHT: 2pt; FONT-FAMILY: Calibri,Arial; FONT-SIZE: 11pt" border=1 cellSpacing=0 cellPadding=0><COLGROUP><COL style="WIDTH: 30px; FONT-WEIGHT: bold"><COL style="WIDTH: 234px"><COL style="WIDTH: 100px"></COLGROUP><TBODY><TR style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt; FONT-WEIGHT: bold"><TD> </TD><TD>A</TD><TD>B</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">1</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">1234-5678-Barrack Obama</TD><TD style="BACKGROUND-COLOR: #99cc00">Barrack Obama</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">2</TD><TD style="FONT-FAMILY: Verdana; FONT-SIZE: 10pt">4567-7655-124678-Ben Bernanke</TD><TD style="BACKGROUND-COLOR: #99cc00">Ben Bernanke</TD></TR></TBODY></TABLE>


<TABLE style="BORDER-BOTTOM-STYLE: groove; BORDER-BOTTOM-COLOR: #00ff00; BORDER-RIGHT-STYLE: groove; BACKGROUND-COLOR: #fffcf9; BORDER-TOP-COLOR: #00ff00; FONT-FAMILY: Arial; BORDER-TOP-STYLE: groove; COLOR: #000000; BORDER-RIGHT-COLOR: #00ff00; FONT-SIZE: 10pt; BORDER-LEFT-STYLE: groove; BORDER-LEFT-COLOR: #00ff00"><TBODY><TR><TD>Spreadsheet Formulas</TD></TR><TR><TD><TABLE style="FONT-FAMILY: Arial; FONT-SIZE: 9pt" border=1 cellSpacing=0 cellPadding=2><TBODY><TR style="BACKGROUND-COLOR: #cacaca; FONT-SIZE: 10pt"><TD>Cell</TD><TD>Formula</TD></TR><TR><TD>B1</TD><TD>=SUBSTITUTE(AlphaNum(A1,TRUE),"-","")</TD></TR><TR><TD>B2</TD><TD>=SUBSTITUTE(AlphaNum(A2,TRUE),"-","")</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>

Code:
Function AlphaNum(txt As String, Optional Alpha As Boolean = True) As String
'Use in cell like _
=AlphaNum(A1,True) '<- True for Alphabets, False for Numbers
With CreateObject("VBScript.RegExp")
    .Pattern = IIf(Alpha, "\d+", "\D+")
    .Global = True
    AlphaNum = .Replace(txt, "")
End With
End Function
 
Upvote 0
My first crack at Regex ( with PGC's base code) was:
Code:
Function UC(s As String) As String 'Finds Name with Proper Case
'user must activate Microsoft vbscript regular expressions 5.5 in Tools / References
Application.Volatile
With CreateObject("VBScript.RegExp")
  .Pattern = "(\b[A-Z]\w*\s\b[A-Z]\w*)"
  If .Test(s) Then UC = .Execute(s)(0).SubMatches(0)
End With
End Function

then use
Code:
=UC(A1)
 
Upvote 0
My first crack at Regex ( with PGC's base code) was:
Code:
Function UC(s As String) As String 'Finds Name with Proper Case
'user must activate Microsoft vbscript regular expressions 5.5 in Tools / References
Application.Volatile
With CreateObject("VBScript.RegExp")
  .Pattern = "(\b[A-Z]\w*\s\b[A-Z]\w*)"
  If .Test(s) Then UC = .Execute(s)(0).SubMatches(0)
End With
End Function

then use
Code:
=UC(A1)

Nice 1 m8.

Biz
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,292
Members
452,902
Latest member
Knuddeluff

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