Remove trailing spaces without losing middle spaces

simoncr

New Member
Joined
Sep 29, 2017
Messages
4
Hi
I have been trying, unsuccessfully, to remove trailing spaces from a set of numbers (all are 10 Characters) whilst keeping any spaces that may exist in the middle.
TRIM does not work because some of the numbers have 2 spaces in the middle and the TRIM function removes one of these.
I would be very grateful if someone could provide a solution.
Thanks in advance.

example of number set below:
03685
040710
089284632
0893221
0893870004
089947002
03685 12
03685 14
0124 5
0124 6

<tbody>
</tbody><colgroup><col></colgroup>
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I can't think of a formula, but if a UDF is OK, this post: http://www.mrexcel.com/archive/Formulas/26078.html has the answer:

Posted by mseyf on August 08, 2001 11:47 AM

Martin:

unfortunately, RTrim (and LTrim) are VBA commands, but if you're not adverse to using a UDF, you could try something like:

Function uTrim(cell)
uTrim = RTrim(cell.Value)
uTrim = LTrim(uTrim)
End Function

you can copy this into a VBA module and use the utrim() command in your sheet.

HTH

Mark
 
Upvote 0
I thought Application.Trim doesn't remove internal spaces but WorkSheetFunction.Trim does, if so is this not better rather than using both LTrim and RTrim?
 
Upvote 0
You are welcome!
Glad we could help.
 
Upvote 0

Forum statistics

Threads
1,215,353
Messages
6,124,463
Members
449,163
Latest member
kshealy

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