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
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
How about

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

edited to replace A1 with C9
 
Last edited:
Upvote 0
Alternatively if the format of the data is always x-xxxx then simply

=LEFT(C9,6)
 
Upvote 0
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.
 
Upvote 0
Thanks both, used first example and worked perfectly
.
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,034
Members
448,940
Latest member
mdusw

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