ampersand operator unexpectedly trims?

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
 
B

Bob Kilmer

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
 
M

mudraker

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 _
 
W

Woody

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 _
 
M

mudraker

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
 
Top