Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default String concatenation

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_<space1
START_<space2 .....and so on

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

shi

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default String concatenation

Use

Sname = Sname & "START_" & Str(i) & ", "


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"shishi" wrote in message
oups.com...
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_<space1
START_<space2 .....and so on

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

shi



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default String concatenation

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default String concatenation

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



"shishi" wrote in message oups.com...
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_<space1
START_<space2 .....and so on
Excel is placing a space between the arguments. The desired results is
START_1, START_2 etc.
shi
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help With String Concatenation Rick Rothstein Excel Worksheet Functions 6 September 15th 11 10:42 PM
Need Help With String Concatenation Xt Excel Worksheet Functions 1 September 15th 11 09:47 PM
Bold in string concatenation Steen Excel Discussion (Misc queries) 12 November 7th 06 12:49 AM
How do I put each member of string concatenation in its own line? DViolette Excel Worksheet Functions 3 July 8th 05 02:08 AM
string concatenation Mike NG Excel Programming 2 August 15th 03 03:06 AM


All times are GMT +1. The time now is 01:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"