String concatenation

S

shishi

Hi,

Is there a better way to concatenate strings in excel vba.
The below code is not giving me the desired results. Could you please
tell what could be the reason?

For i = 1 To nmodules

Sname = "START_" & Str(i)
MsgBox "The String is " & Sname
Next i

The result is
START_<space>1
START_<space>2 .....and so on

Excel is placing a space between the arguments. The desired results is
START_1, START_2 etc.

shi
 
S

shishi

Hi Mr. Pearson,

I tried using the above solution, still the excel is placing a space
between START_ and 1. So I get results like START_ 1. Any more ideas??

Thanks,
Shi
 
J

Jim Cone

Shi,

I think Chip may have gone to dinner...

The "Str" function automatically adds a space to contain the sign of the number.
The "Cstr" function would work for you, however it is not required.
The "&" operator will convert the i variable to a string so,
assuming that Sname is a String...

Sname = "START_" & i

is all you need.

Jim Cone
San Francisco, USA



Hi,
Is there a better way to concatenate strings in excel vba.
The below code is not giving me the desired results. Could you please
tell what could be the reason?
For i = 1 To nmodules
Sname = "START_" & Str(i)
MsgBox "The String is " & Sname
Next i
The result is
START_<space>1
START_<space>2 .....and so on
Excel is placing a space between the arguments. The desired results is
START_1, START_2 etc.
shi
 

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

Top