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:
[TABLE="width: 99"]
<tbody>[TR]
[TD]03685 [/TD]
[/TR]
[TR]
[TD]040710 [/TD]
[/TR]
[TR]
[TD]089284632 [/TD]
[/TR]
[TR]
[TD]0893221 [/TD]
[/TR]
[TR]
[TD]0893870004[/TD]
[/TR]
[TR]
[TD]089947002 [/TD]
[/TR]
[TR]
[TD]03685 12[/TD]
[/TR]
[TR]
[TD]03685 14[/TD]
[/TR]
[TR]
[TD]0124 5[/TD]
[/TR]
[TR]
[TD]0124 6[/TD]
[/TR]
</tbody><colgroup><col></colgroup>[/TABLE]
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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