• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

Excell 2002 VBA "Trim" commands don't work to remove trailing blanks.

I want my macro to remove trailing blanks from lists of names.  When I type RTrim(A) or Trim(A) as soon as I go to the next line of code the variable separates from the command, i.e., RTrim (A) and doesn't work.  What is an alternate code to remove the last character of a string, in this case a blank?
Thanks
0
RogerKMiller
Asked:
RogerKMiller
  • 2
  • 2
1 Solution
 
spattewarCommented:
Hello RogerKMiller,

have you assigned it to a variable?
for e.g.

varA = RTRIM(A)

--varA should then contain the trimmed string which can be used further.

Regards,

spattewar
0
 
DaveCommented:
I'm not sure why you can't use your varaible down the code  ???
YourVar = Left$(YourVar, Len(YourVar) - 1)

Open in new window

0
 
RogerKMillerAuthor Commented:
FOR SOME REASON THAT DIDN'T WORK.
For X = 1 To 4
varA = RTrim(Cells(X, 1))
varB = RTrim(Cells(X, 2))
Next X
0
 
DaveCommented:
If you loop without using varA  and varB then they are lost  ....  your code above effectively is
varA = RTrim(Cells(4, 1))
varB = RTrim(Cells(4, 2))
 
suggest you need a pathway using these strings

FOR SOME REASON THAT DIDN'T WORK.
For X = 1 To 4
varA = RTrim(Cells(X, 1))
varB = RTrim(Cells(X, 2))
'do something with variables
Next X

Open in new window

0
 
RogerKMillerAuthor Commented:
Thanks for your accuracy and speedy availability.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now