Trim function ?

bflan0524

Board Regular
Joined
Oct 7, 2016
Messages
188
Office Version
  1. 2010
i am not sure if this would be a trim function or not. if somebody could help that would be great.
if i have in column A the following 4-Very Satisfied. how would i get that column to just show the 4 in another column?

thank you
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

FDibbins

Well-known Member
Joined
Feb 16, 2013
Messages
6,723
If there might be more than a 1-digit number, that wont work...
14-Very Satisfied
will return 1

If there will always be a -, you can use that to ID where the number ends...

=left(A2,search(("-",A2)-1)
 
Upvote 0

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,150
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
If there might be more than a 1-digit number, that wont work...
14-Very Satisfied
will return 1

If there will always be a -, you can use that to ID where the number ends...

=left(A2,search(("-",A2)-1)
One parenthesis too many, here is the corrected formula using FIND instead of SEARCH...

=LEFT(A2,FIND("-",A2)-1)
 
Upvote 0

FDibbins

Well-known Member
Joined
Feb 16, 2013
Messages
6,723
ooops - again, thanks

I have got into the habit of using SEARCH, because it is not case-sensitive, so now, unless I specifically need to check for "case", I use SEARCH
 
Upvote 0

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,150
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
I have got into the habit of using SEARCH, because it is not case-sensitive, so now, unless I specifically need to check for "case", I use SEARCH
While I have seen others claim the contrary, it is my belief that FIND is faster than SEARCH because it has much less to do under the hood in order to perform its intended function (at least that is the case in the VBA world with functions having options related to case sensitivity, so it seems natural to assume that the same would apply in the formula world).
 
Upvote 0

hiker95

Well-known Member
Joined
Apr 8, 2009
Messages
17,649
bflan0524,

How about something like this?


Excel 2007
ABCD
14-Very Satisfied444
214-Very Satisfied141414
323414-Very Satisfied234142341423414
4
Sheet1
Cell Formulas
RangeFormula
B1=IFERROR(LEFT(A1,IFERROR(FIND("-",A1)-1,FIND("-",A1)-1)),"")+0
C1=VALUE(TRIM(MID(SUBSTITUTE($A1,"-",REPT(" ",100)),1,100)))
D1=SUBSTITUTE(TRIM(LEFT(RIGHT(SUBSTITUTE(A1,"-",REPT(" ",99)),198),99)),"-","")+0



The formulae in cells B1, C1, and, D1, copied down.
 
Upvote 0

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,210
@hiker95

Why to go to such lengths?

B1 is expensive...

Either...

=LEFT(A1,FIND("-",A1&"-")-1)

Or...

=LEFT(A1,SEARCH("-",A1&"-")-1)

would suffice as suggested by other helpers.

The formulas that you offer in C1 and D1 looks like we are doing "numerology". The 100 of C1 becomes for no obvious reason 99 in D1, for example.
 
Upvote 0

Forum statistics

Threads
1,191,131
Messages
5,984,845
Members
439,918
Latest member
engrnoir

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