Removing spaces within cells but only at the end of the data string

SteveNL86

Board Regular
Joined
Nov 11, 2014
Messages
109
Office Version
  1. 2016
Platform
  1. Windows
Dear reader,

I'm dealing with a workbook imported from a SQL database but I've noticed that sometimes there is an extra space within cells.
So I will have a 'Smith, J. ' instead of just 'Smith, J.'. This is breaking some of the formula's I'm using.

The sheet is rather large, is there a quick way I can remove spaces within all the cells but only if they occur at the end of the data string?

Any help is much appreciated!

Kind regards,
Steve
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Is it a normal space or some other character?
What do you get if you use
Excel Formula:
=code(right(A2))
change A2 to references one of the cells with an extra space
 
Upvote 0
It's just a normal space.

I get this:


46​
46​
32​
110​
32​
110​
32​
32​
32​
110​
101​
32​
32​
32​
32​
32​
32​
32​
32​
 
Upvote 0
Ok, how about
VBA Code:
Sub SteveNL()
   With Range("A2", Range("A" & Rows.Count).End(xlUp))
      .Value = Evaluate("trim(" & .Address & ")")
   End With
End Sub
 
Upvote 0
Solution
Thanks Fluff, seems to have done the trick!

Thanks for the help!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,747
Members
448,989
Latest member
mariah3

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