How can I concatenate strings in VBA?
Solution 1:
&
is always evaluated in a string context, while +
may not concatenate if one of the operands is no string:
"1" + "2" => "12"
"1" + 2 => 3
1 + "2" => 3
"a" + 2 => type mismatch
This is simply a subtle source of potential bugs and therefore should be avoided. &
always means "string concatenation", even if its arguments are non-strings:
"1" & "2" => "12"
"1" & 2 => "12"
1 & "2" => "12"
1 & 2 => "12"
"a" & 2 => "a2"
Solution 2:
The main (very interesting) difference for me is that:"string" & Null
-> "string"
while"string" + Null
-> Null
But that's probably more useful in database apps like Access.