delete space in end of words

reza_doang

Board Regular
Joined
May 31, 2010
Messages
187
hi all,

how to delete space in the end of words, sample:
1. apple
2. apple

in no. 2 there is space after apple, how to delete using vba, since there is many space in 1 column.

hope you understand....

thank you
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Please try on a copy of your data first...

Code:
With Intersect(ActiveSheet.UsedRange,Columns("A"))
    .Value = Evaluate("if(row(),if(len(" & .Address & "),trim(" & .Address & "),""""))")
End With
 
Upvote 0
Please try on a copy of your data first...

Code:
With Intersect(ActiveSheet.UsedRange,Columns("A"))
    .Value = Evaluate("if(row(),if(len(" & .Address & "),trim(" & .Address & "),""""))")
End With

HI Jon..
thanks for your response, but can you be more specific, i don't know about programming....how to run it? where should i put this macro?

thank you
 
Upvote 0
HI Jon..
thanks for your response, but can you be more specific, i don't know about programming....how to run it? where should i put this macro?

thank you

Right-click your sheet tab and click 'View Code'. The VBE should open. Next go insert > new module. Paste this code into the code pane that opens:

Code:
Sub TrimText()
    With Intersect(ActiveSheet.UsedRange, Columns("A"))
        .Value = Evaluate("if(row(),if(len(" & .Address & "),trim(" & .Address & "),""""))")
    End With
End Sub

Change Columns("A") to reference the column that contains the text with trailing spaces.

Hit Alt+Q to close the VBE

Now, make sure that the sheet with the trailing spaces is active.
Press Alt+F8 and run the macro called 'TrimText'.

Please remember to take a copy of your sheet first.
 
Upvote 0
Code:
With Intersect(ActiveSheet.UsedRange,Columns("A"))
    .Value = Evaluate("if(row(),if(len(" & .Address & "),trim(" & .Address & "),""""))")
Why the "if(row(),...) part? This seems to work just as well...

Code:
.Value = Evaluate("if(len(" & .Address & "),trim(" & .Address & "),"""")")
 
Upvote 0
Right-click your sheet tab and click 'View Code'. The VBE should open. Next go insert > new module. Paste this code into the code pane that opens:

Code:
Sub TrimText()
    With Intersect(ActiveSheet.UsedRange, Columns("A"))
        .Value = Evaluate("if(row(),if(len(" & .Address & "),trim(" & .Address & "),""""))")
    End With
End Sub

Change Columns("A") to reference the column that contains the text with trailing spaces.

Hit Alt+Q to close the VBE

Now, make sure that the sheet with the trailing spaces is active.
Press Alt+F8 and run the macro called 'TrimText'.

Please remember to take a copy of your sheet first.

thanks jon, works well
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,547
Members
452,925
Latest member
duyvmex

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