As PHV suggests, you can use Trim(MyStr), but be aware this will affect double spacings within the string too. Same goes for the solution posted by missinglinq. For example:
" My String "
gets changed to:
"My String"
If preserving any internal double spacing is important, you could achieve that via:
LTrim(RTrim(MyString))
PHV is correct! The QuickBasic4.5 (which VB and VBA was based on) LTRIM and RTRIM removes spaces from either end of the string, preserving "internal" spacing. TRIM simply combines these two functions! The caveat about my answer is valid.
It is the Excel Worksheet Trim Function which removes multiple internal spaces.
Enjoy,
Tony
-------------------------------------------------------------------------------------------- We want to help you; help us to do it by reading this: Before you ask a question.
Indeed we are! I was just pointing out the probable source of the confusion - and it could be used in VBA.
Enjoy,
Tony
-------------------------------------------------------------------------------------------- We want to help you; help us to do it by reading this: Before you ask a question.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.