Extracting text before a specific character and deleting the rest

DHLITTLE

New Member
Joined
Jun 12, 2018
Messages
2
I have a text field for example:

There are 8% of people who wear red

I'd like to extract whatever number is before the "%" sign.

I got as far as [FONT=&quot]=MID([/FONT][FONT=&quot]AJ2[/FONT][FONT=&quot],FIND[/FONT][FONT=&quot]([/FONT][FONT=&quot]"%",[/FONT][FONT=&quot]AJ2[/FONT][FONT=&quot])[/FONT][FONT=&quot]-3,LEN[/FONT][FONT=&quot]([/FONT][FONT=&quot]AJ2[/FONT][FONT=&quot])[/FONT]) which kind of works but leaves everything after the % sign. I just want the number ideally.

Also some of the numbers are 12.3% others might be 1% so simply extracting the 3 characters before the % sign doesn't work reliably.

Is there a better way of doing this?

Thanks in advance.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Welcome to the board. Perhaps this:

=TRIM(MID(SUBSTITUTE(AJ2," ",REPT(" ",99)),FIND("%",SUBSTITUTE(AJ2," ",REPT(" ",99)))-5,6))

So long as there is only one % in each string. Also, change the 6 to 5 if you don't want to include the %.
 
Last edited:
Upvote 0
Hi,

Another way, result converted to Real Number in case of further comparison and/or math:

Also, this formula Won't fail in case the 8% is at the beginning of the Text string.


Book1
AB
1There are 8% of people who wear red8
28% of people wear red8
3People who wear read is 8%8
Sheet69
Cell Formulas
RangeFormula
B1=RIGHT(SUBSTITUTE(LEFT(A1,FIND("%",A1)-1)," ",REPT(" ",15)),15)+0
 
Last edited:
Upvote 0
In light of jtakw's findings, here is a slightly modified version that will not fail if the % is at the beginning of the string. And a version converting to number for calculations.

=TRIM(MID(SUBSTITUTE(AJ2," ",REPT(" ",99)),MAX(1,FIND("%",SUBSTITUTE(AJ2," ",REPT(" ",99)))-4),5))

=TRIM(MID(SUBSTITUTE(AJ2," ",REPT(" ",99)),MAX(1,FIND("%",SUBSTITUTE(AJ2," ",REPT(" ",99)))-4),5))+0
 
Upvote 0
In light of jtakw's findings, here is a slightly modified version that will not fail if the % is at the beginning of the string. And a version converting to number for calculations.

=TRIM(MID(SUBSTITUTE(AJ2," ",REPT(" ",99)),MAX(1,FIND("%",SUBSTITUTE(AJ2," ",REPT(" ",99)))-4),5))

=TRIM(MID(SUBSTITUTE(AJ2," ",REPT(" ",99)),MAX(1,FIND("%",SUBSTITUTE(AJ2," ",REPT(" ",99)))-4),5))+0

Thank you both for your help, it is incredibly helpful.
 
Upvote 0
Thank you both for your help, it is incredibly helpful.

You're welcome, welcome to the forum.

Remove the -1 within my formula in Post #3 if you want the %, format result cells as "percentage":


Book1
ABC
1There are 8% of people who wear red88%
28% of people wear red88%
3People who wear read is 8%88%
Sheet69
Cell Formulas
RangeFormula
B1=RIGHT(SUBSTITUTE(LEFT(A1,FIND("%",A1)-1)," ",REPT(" ",15)),15)+0
C1=RIGHT(SUBSTITUTE(LEFT(A1,FIND("%",A1))," ",REPT(" ",15)),15)+0
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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