LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.office.developer.vba
external usenet poster
 
Posts: 4,624
Default subroutine to concatenate strings

One way:

Public Sub Concat(rng As Range)
Dim rCell As Range
Dim sOut As String
For Each rCell In Selection
sOut = sOut & "," & rCell.Text
Next rCell
rng.Value = Mid(sOut, 2)
End Sub


In article ,
"MAB" wrote:

I want to write a subroutine/macro that will execute on a selected range of
cells ( of a single column ). That range will be passed to the subroutine
and the sub will concatenate all the values of the cells within the range
with commas "," seperating each value. And finally the sub will place the
resulting string say in cell A1. for example If I select range A4:A6 which
contain values 4,5,6 respectively then when I run the macro/sub the
resulting string "4,5,6" should appear in A1. how can that be done. I can do
the concatenation part but dont know about working on selected ranges.

Note: The range sould be passed as argument to the sub and the range does
not span multiple columns.


thx

 
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
Concatenate strings? Alain Dekker Excel Discussion (Misc queries) 4 February 21st 10 08:51 PM
CONCATENATE I have two text strings in cells but it wont work paintsr Excel Discussion (Misc queries) 1 January 23rd 09 04:30 PM
concatenate strings Gary''s Student Excel Worksheet Functions 3 September 15th 05 05:25 PM
space between text strings with concatenate Jeff Excel Discussion (Misc queries) 2 March 3rd 05 06:54 PM
Concatenate a strings range. y Excel Programming 3 April 26th 04 04:30 AM


All times are GMT +1. The time now is 12:17 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"