ampersand operator unexpectedly trims?

  • Thread starter Thread starter Woody
  • Start date Start date
W

Woody

In the immediate window, I input:

? "_" & " abc " & "_"

and it returns:

_ abc _


Why did it knock off all but one of the spaces off the right side of the
middle string?

Thanks,
Woody
 
It looks like it has something to do with the underscores. For instance:

?"_ _"
_ _

?"' '"
' '

?"_ '"
_ '

?">" Space(10) "<"

? "_" Space(10) "_"
_ _

? "_"; Space(10); "_"
_ _

? "_" Tab(10) "_"
_ _

? ">" Tab(10) "<"


using Win 2K, Excel 2002
 
Woody

you only have one space before abc and one after abc which is what the
return result shows

"_" & " abc " & "_"

gives a string of

_ abc _
 
how do you explain this?

? "_"; Space(10); "_"
_ _

or this?

?"_ _"
_ _
 
Woody

you only have one space before abc and one after abc which is what the
return result shows

"_" & " abc " & "_"

gives a string of

_ abc _

no, there are 3 spaces before and after "abc". This should make it more
obvious:

?"_" & space(3) & "abc" & space(3) & "_"
_ abc _
 
I don't know the correct answer but I beleive it has to do with VB
using _ as the symbol theat the line of code is continued on to th
next line and VBA automatically removing all extra spaces betwee
operators
 

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

Back
Top