I'm trying to concatenate a bunch of columns in Excel. I know I can manually do with:
=A1&", "&B1&", "&C1
(and so on)
but I have about 40 columns, and I'm looking for a way to streamline this process.
Thanks in advance for any help!
I'm trying to concatenate a bunch of columns in Excel. I know I can manually do with:
=A1&", "&B1&", "&C1
(and so on)
but I have about 40 columns, and I'm looking for a way to streamline this process.
Thanks in advance for any help!
When concatenating a range single row or column you can do this in a single shot using
Application.Transpose
to avoid range loopsThis UDF has three arguments
,
is used if there is no entrey)TRUE
for a range - which on further thought I will update the UDF to automatically detect whether the range isrow
ORcolumn
BASED)Note that in terms of the other answers
IIF
evaluates both theTRUE
andFALSE
arguments asVBA
doesn't [short circuit]( http://en.wikipedia.org/wiki/Short-circuit_evaluation). SoIFF
can be expensive inside loopscode
In the example below
D1
) is=concat(A1:C1,",",TRUE)
E1
is=concat(E3:E5,", ")
Let me post my function too. I've run into this problem as well in the past.
My problem usually arise when I try to concatenate dates, errors and blank cells.
So I try to cover most of those using below:
As of now, I've not encountered a cell entry this function cannot concatenate.
Feel free to adjust to your needs or hearts content. HTH.
You can always use Visual Basic For Applications (VBA). It is microsofts language for Office. Here is an example of what you might be looking for but try the Google Machine to learn more about VBA and how to input this code into your spreadsheet.
Sub ConcatColumns()
Do While ActiveCell <> "" 'Loops until the active cell is blank.
Loop
End Sub
As a user function taking a
range
Changing the
Variant
types, if you need to (tostring
, most likely).Use like this:
I would use vba for this. For each column you would want something like (assuming values are in row 1)
myString will then have the contents of your concatenated string.