delete blank space after surnames!

Cake

New Member
Joined
Jul 5, 2004
Messages
13
maaaan this is annoying! as usual I am hoping that an expert can give me a quick answer as opposed to my useless fiddling!

I have a sheet of around 3000 names in column a and am de-duping them, the only problem is that some of the cells have spaces after the surname, therefore the =a3=a2 to get a true or false doesn't work.

I have tried various Trim / Len features but seem to be missing the point!

example:

a2 = jon smith
a3 = jon smith_ (where _ indicates a space after the name)

Is there code that can remove any blank spaces from the right of the text string?

As ever really greatful for help! :)
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Zack Barresse

MrExcel MVP
Joined
Dec 9, 2003
Messages
10,881
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
Yes. You can download/install ASAP Utilities which has this function already, or run something like this ...


Code:
Option Explicit

Sub RemoveLeadingTrailingSpaces()
    Dim cel As Range, rng As Range
    Set rng = Selection
    For Each cel In rng
        If Not IsNumeric(cel) Or Not cel.HasFormula Then
            cel.Text = Trim$(cel.Text)
            End If
        Next cel
End Sub
Note this assumes you will select the range first, then run the above code.


HTH
 

Nimrod

MrExcel MVP
Joined
Apr 29, 2002
Messages
6,259
Sub TrimString()
For Each Nam In Columns("A:A").SpecialCells(xlCellTypeConstants, 2)
Nam.Value = Trim(Nam.Value)
Next Nam
End Sub
 

Cake

New Member
Joined
Jul 5, 2004
Messages
13
awesome, thanks guys...the solution from Nimrod did the trick...appreciate both responses! :LOL:
 

Watch MrExcel Video

Forum statistics

Threads
1,123,402
Messages
5,601,475
Members
414,452
Latest member
Dannysamworth

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
Top