Application trim or rtrim

H

Hennie Neuhoff

I've imported file to Excel. I've tried, without sucess, to delete trailing
blanks. I tried RTrim, Application.Trim but still have these blaks or spaces
at the end. Any suggestions?
Thanks in advance
 
R

Rick Rothstein

You probably do not have spaces at the end of your text. My guess is you got
your text from the web and there are characters with ASCII code 160 where
you think there are spaces. Put this code immediately after you assign the
text to your variable (since you didn't post the variable's name, I'll use
YourVariable for it in the code)...

For XX = 1 To Len(YourVariable)
Debug.Print "<" & Mid(YourVariable, XX, 1) & ">" & _
" - " & Asc(Mid(YourVariable, XX, 1))
Next

and then look in the Immediate window to see what the ASCII code is for
those characters. If I am right, you can use this statement...

YourVariable = Trim(Replace(YourVariable, Chr(160), ""))

to get rid of them and any spaces that remain after the replacement. If you
have something other than ASCII 160 characters, then use their ASCII code in
the above line of code instead.
 
J

JSnow

I had been struggling with this same problem for the last 24 hours. Very
very glad to read your post Rick. For my problem, I replaced character(160)
with " " and then RTrimmed the heck out of my rows.

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top