Trim after characters

Kesser

New Member
Joined
Sep 18, 2020
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hi

I have the below data where I want to trim the last "-2), if it appears.
6-2891
5-4795
4-5523-2
7-5533

Ordinarily I have used the below but only works if the rule is the same
=LEFT(C9,LEN(C9)-SEARCH("-",C9))

What can I use if it is in only selected cells in which I want to trim the string, so the non "-2" do not get trimed also

Thanks
 

Some videos you may like

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

JimM

Well-known Member
Joined
Nov 11, 2003
Messages
686
How about

=IF(RIGHT(C9,2)="-2",LEFT(C9,LEN(C9)-2),C9)

edited to replace A1 with C9
 
Last edited:

JimM

Well-known Member
Joined
Nov 11, 2003
Messages
686
Alternatively if the format of the data is always x-xxxx then simply

=LEFT(C9,6)
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
Hi

Do you really mean "-2" or do you mean anything after a second "-" like

4-5523-2 -> 4-5523
4-123-5 -> 4-123
4-54-ABC -> 4-54

Also look at Jim's second post if the first 2 groups of digits are fixed length.
 

Kesser

New Member
Joined
Sep 18, 2020
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Thanks both, used first example and worked perfectly
.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,816
Messages
5,598,264
Members
414,221
Latest member
MD1222

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