Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
King
 
Posts: n/a
Default Concatenate a range

How do you concatenate an entire range at once?

=CONCATENATE(A1:A10) entered as array still only returns
the first element, A1.

There has to be something better than -

=CONCATENATE(A1,A2,A3,A4,A5,...A10)

Thanks
  #2   Report Post  
Jason Morin
 
Posts: n/a
Default

Use a simple UDF like this:

Function Concatall(rng As Range) As String
Dim cell As Range
For Each cell In rng
Concatall = Concatall & cell.Text
Next
End Function

---
Call as =Concatall(A1:A10)

HTH
Jason
Atlanta, GA

-----Original Message-----
How do you concatenate an entire range at once?

=CONCATENATE(A1:A10) entered as array still only returns
the first element, A1.

There has to be something better than -

=CONCATENATE(A1,A2,A3,A4,A5,...A10)

Thanks
.

  #3   Report Post  
King
 
Posts: n/a
Default


-----Original Message-----
Use a simple UDF like this:

Function Concatall(rng As Range) As String
Dim cell As Range
For Each cell In rng
Concatall = Concatall & cell.Text
Next
End Function

---
Call as =Concatall(A1:A10)

HTH
Jason
Atlanta, GA

-----Original Message-----
How do you concatenate an entire range at once?

=CONCATENATE(A1:A10) entered as array still only returns
the first element, A1.

There has to be something better than -

=CONCATENATE(A1,A2,A3,A4,A5,...A10)

Thanks
.

.


That works. Thank you.
  #4   Report Post  
Harlan Grove
 
Posts: n/a
Default

Jason Morin wrote...
Use a simple UDF like this:

Function Concatall(rng As Range) As String
Dim cell As Range
For Each cell In rng
Concatall = Concatall & cell.Text
Next
End Function

....

Or generalize,


Function mcat(ParamArray s()) As String
'Copyright (C) 2002, Harlan Grove
'This is free software. It's use in derivative works is covered
'under the terms of the Free Software Foundation's GPL. See
'http://www.gnu.org/copyleft/gpl.html
'------------------------------------
'string concatenation analog to SUM
Dim r As Range, x As Variant, y As Variant

For Each x In s
If TypeOf x Is Range Then
For Each r In x.Cells
mcat = mcat & r.Value
Next r
ElseIf IsArray(x) Then
For Each y In x
mcat = mcat & IIf(IsArray(y), mcat(y), y)
Next y
Else
mcat = mcat & x
End If
Next x
End Function


which allows expressions like

=mcat("hi",(A1:A4,A6:D6,C2),"foo",A7:F9)

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
create range bar graph Aussie1497 Charts and Charting in Excel 2 April 26th 23 11:47 AM
Passing a range name as an argument to the Index Function Michael Sharpe Excel Discussion (Misc queries) 3 September 5th 12 01:33 PM
Dynamic Print Range Help waxwing Excel Worksheet Functions 2 February 21st 05 03:47 PM
Define a range based on another named range Basil Excel Worksheet Functions 2 February 21st 05 01:47 PM
named range refers to: in a chart Spencer Hutton Excel Discussion (Misc queries) 1 December 14th 04 10:15 PM


All times are GMT +1. The time now is 02:37 AM.

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

About Us

"It's about Microsoft Excel"