Remove Spaces at the end of text

BaconMcSandwich

New Member
Joined
Jun 14, 2021
Messages
16
Office Version
  1. 365
Platform
  1. Windows
I need a way to remove the trialing spaces at the end of some alpha numeric text strings.
However the strings are random lengths, sometimes ending in numbers, sometimes letters, and sometimes include double spaces within the string. All this needs to be kept the same but the end spaces removed.
(Annoyingly I found a simple formula to do this and didn’t save the info ?‍♂️)

Below are some rough examples with spaces replaced with dashes. It’s just the trialing spaces that need removing, everything else needs to stay.
String examples:
AU12H17-AJDM—1——
AU12USUHWIJS———
AU12IWJ—-IJ12M—
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
You can use the TRIM worksheet function …​
 
Upvote 0
You can use the TRIM worksheet function …​
Trim will remove the double spaces in the middle of the strings. Which I don’t want to happen.
This is the problem as almost every search suggest trim.
 
Upvote 0
You could use a UDF
VBA Code:
Function Bacon(Cl As Range) As String
   Bacon = RTrim(Cl)
End Function
+Fluff 1.xlsm
AB
1
2abc 123 abc 123
3AU12H17 AJDM 1 AU12H17 AJDM 1
4AU12USUHWIJS AU12USUHWIJS
5AU12IWJ IJ12M AU12IWJ IJ12M
Main
Cell Formulas
RangeFormula
B2:B5B2=bacon(A2)
 
Upvote 0
Here's another option you could try.

Excel Formula:
=LEFT(A1,MAX(IF(MID(A1,SEQUENCE(LEN(A1)),1)<>" ",SEQUENCE(LEN(A1)))))
 
Upvote 0

Forum statistics

Threads
1,214,891
Messages
6,122,101
Members
449,066
Latest member
Andyg666

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