Trim Characters Other Than An Empty Space At The End Of A Cell

K

K8_Dog

In my data, I have some cells that end in " - " (space dash space). I would
like to delete the space dash space if it is the last thing in the cell. I
would like to keep it if it is in the middle. I know that the TRIM function
deletes a trailing space, can I edit it to delete a trailing space dash
space? Here's an example:

Mary - poodle
Theo - beagle
Barney -
Jacob - pug
Schmitty -

So, I want "Mary - poodle" to stay the same, and "Barney - " to become just
"Barney" like this

Mary - poodle
Theo - beagle
Barney
Jacob - pug
Schmitty

Thank you!
 
R

RagDyer

With data in Column A, try this in B1:

=IF(RIGHT(A1,3)=" - ",LEFT(A1,LEN(A1)-3),A1)

And copy down as needed.

To remove the formulas and leave the data behind, copy Column B,
then Paste Special, Values, <OK>, <Esc>.
 
P

Pete_UK

Put this formula in an adjacent column:

=IF(RIGHT(A1,3)=" - ",LEFT(A1,LEN(A1)-3),A1)

Then copy this down as required.

Hope this helps.

Pete
 
T

Tyro

If your cells end with " - ", space-dash-space then:

=IF(RIGHT(A1,3)=" - ",LEFT(A1,LEN(A1)-3),A1)
 
K

K8_Dog

Thanks everyone,
This solution is perfect. LEN is new to me and so cool!
Thanks,
K8Dog
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top