Remove only one space, if there is a space, from the end of text.

pglufkin

Board Regular
Joined
Jun 19, 2005
Messages
127
Was wondering if someone could help me.

Was thinking something along the lines of the procedure below, but I only want to remove one space at the end of my text within a cell, if there is a space. Any quick ideas? Thx.

Code:
Sub hth() 
    Dim c As  Range 
     
    For Each c In Range("H1", Range("H" & Rows.Count).End(xlUp)) 
        c.Value = Trim(c.Value) 
    Next c 
End Sub
 
It is simply a "stand-in" character for the address (you can use any character that will not be included in the argument's text) that gets replaced all at once by the Replace function... it avoids having to concatenate the address into the argument's text string over and over again which makes constructing/reading the argument a little easier.

Thank you for the explanation!

I'll try to use in the future.

M.
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Thank you for the explanation!

I'll try to use in the future.
Actually, the idea to do that was not original with me, but I cannot remember who introduced me to the idea... I think it was one of the Peters in this forum (maybe Peter_SSs?)... I tried Google'ing it, but could not find a satisfactory search string. Anyway, I though it was a good idea when I first was told about it and have tried to remember to adopt it in my own code (but old habits die hard and often I find myself doing what I had always done previously... concatenating like crazy all over the place :LOL:).
 
Upvote 0
In fact i'm not sure i fully understood the concept.

@ sustitutes the address, not the value, is it?

Probably when i try to use it in the future i'll make blunders :LOL:

But i dont know other ways to learn new things - trial and error, trial and error...

M.
 
Upvote 0
I'm curious as to why you wouldn't want to remove all the spaces from the end of the cell.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,698
Members
449,117
Latest member
Aaagu

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