Extract text from middle of string using character count

rythmic_flow

New Member
Joined
Jan 16, 2019
Messages
13
Hello,

I would like to extract the name only from a cell that comes through in the following format:

abc123456789 JOE BLOGGS abc123456789

The name can very in length, but the number of characters from the far left and far right of the string always stay the same amount.

Is there a formula that can count characters both from the right and from the left and extract what is in the middle?

Or are any different ways to do this?
 

Some videos you may like

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

sandy666

Banned - Rules violations
Joined
Oct 24, 2015
Messages
7,499
if the name is always in upper case and the rest is in lower case
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table9"]}[Content],
    Result = Table.RemoveColumns(Table.TransformColumns(Table.AddColumn(Source, "Name", each Text.Select([raw], {"A".."Z", " "})),{{"Name", Text.Trim, type text}}),{"raw"})
in
    Result
rawName
abc123456789 JOE BLOGGS abc123456789JOE BLOGGS
 

rythmic_flow

New Member
Joined
Jan 16, 2019
Messages
13
Hi Alpha,

This works for the above sample, but doesn't cover the varying lengths of names.

If the number of characters before and after the name are always a consistent amount, is there a formula that can trim both the first 13 and last 13 characters from a cell?
 

rythmic_flow

New Member
Joined
Jan 16, 2019
Messages
13

ADVERTISEMENT

if the name is always in upper case and the rest is in lower case
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table9"]}[Content],
    Result = Table.RemoveColumns(Table.TransformColumns(Table.AddColumn(Source, "Name", each Text.Select([raw], {"A".."Z", " "})),{{"Name", Text.Trim, type text}}),{"raw"})
in
    Result
rawName
abc123456789 JOE BLOGGS abc123456789JOE BLOGGS
That's a good suggestion, but unfortunately there are variables here too
 

sandy666

Banned - Rules violations
Joined
Oct 24, 2015
Messages
7,499
but unfortunately there are variables here too
you didn't say that in post#1 and it seems your example is not representative
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table9"]}[Content],
    TBD = Table.AddColumn(Source, "Result", each Text.BetweenDelimiters([raw], " ", " ", 0, 1), type text),
    TSC = Table.SelectColumns(TBD,{"Result"})
in
    TSC
result is the same as above
 

rythmic_flow

New Member
Joined
Jan 16, 2019
Messages
13

ADVERTISEMENT

you didn't say that in post#1 and it seems your example is not representative
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table9"]}[Content],
    TBD = Table.AddColumn(Source, "Result", each Text.BetweenDelimiters([raw], " ", " ", 0, 1), type text),
    TSC = Table.SelectColumns(TBD,{"Result"})
in
    TSC
result is the same as above

Thanks for pointing it out. I can't seem to find an edit function to change my original post, but will bear in mind next time.

Regarding your latest formula, is this something that needs to be done within powerquery? I don't have experience with this. Is there a more simple formula using TRIM/MID/LEN function?

A more accurate example would be:

abC-123456789 JOE BLOGGS aBC123456789

Variables: Length of name can change

Consistencies: Number of characters before and after name will be the same each time
 

rythmic_flow

New Member
Joined
Jan 16, 2019
Messages
13
Sandy, looking back at your posts, i'm seeing both your formulas in power query coding now. I don't know what has changed or why i am seeing like this?
 

sandy666

Banned - Rules violations
Joined
Oct 24, 2015
Messages
7,499
first code extracting upper case letter and spaces then trim which is wrong because of post#5
second code extracting string between space before name and space after name
it doesn't count anything
both are M (Power Query)
 

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,400
Hi Alpha,

This works for the above sample, but doesn't cover the varying lengths of names.

If the number of characters before and after the name are always a consistent amount, is there a formula that can trim both the first 13 and last 13 characters from a cell?

=MID(A1,14,LEN(A1)-26)

The formula trims both the first 13 and last 13 characters from a cell regardless of the length of name in between.

What am I missing? Did you try it?
 

Watch MrExcel Video

Forum statistics

Threads
1,127,875
Messages
5,627,407
Members
416,245
Latest member
Xterminat

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
Top