Concatenate an Area (Range)

G

Gilles P (FR)

Hello,

I like concatenate Cells A1 to A3 by using a range "{=Concatenate(A1:A3)}"

I can obtain a by matrix formula a result as
{"valueA1"."ValueA2"."ValueA3"}, but i can't convert it in a text chain
"valueA1ValueA2ValueA3"

I there is a way by formula of matrix calculation ?
If not could you please give me the VBA code to create a function ?

Thanks

Gilles P. (FR)
 
B

Billy Liddel

Don't know a formula but a simple UDF (no error checking)

Function concat(data) As String
Dim c, str As String
For Each c In data
If c = data(1) Then
str = c
Else
str = str & " " & c
End If
Next c
concat = str
End Function

Hope this helps.

Peter Atherton
 
W

wknehans

To use the CONCATENATE function, you can't just specifiy a range, you have to
give it each bit of data individually, separated by a comma. Try this:

=Concatenate(A1,A2,A3)

Should be a lot easier than a matrix calculation....

BD
 
G

Gord Dibben

Billy

Your function returns some strange results if any blank cells or duplicates
in the range.

Try this one.........

Function ConCatRange(CellBlock As Range) As String
Dim Cell As Range
Dim sbuf As String
For Each Cell In CellBlock
If Len(Cell.text) > 0 Then sbuf = sbuf & Cell.text & " "
Next
ConCatRange = Left(sbuf, Len(sbuf) - 1)
End Function


Gord Dibben MS Excel MVP
 

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