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! :)
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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
 
Upvote 0
Sub TrimString()
For Each Nam In Columns("A:A").SpecialCells(xlCellTypeConstants, 2)
Nam.Value = Trim(Nam.Value)
Next Nam
End Sub
 
Upvote 0
awesome, thanks guys...the solution from Nimrod did the trick...appreciate both responses! :LOL:
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,267
Members
448,558
Latest member
aivin

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