View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Concatenate a Range of Cells

I'm a little unclear on where you want the data to end up (example is
A4-which is last row + 1, first column, but you said first row, last column +
1), so I went with last row + 1, first column.

Does this help?

Sub JoinText()
Dim Col As Range
Dim Cell As Range
Dim Result As String

With Selection
For Each Col In .Columns
For Each Cell In Col.Cells
Result = Result & Cell.Value
Next Cell
If Col.Column < .Columns(.Columns.Count).Column Then _
Result = Result & Chr(10)
Next Col
Cells(.Rows(.Rows.Count).Row + 1, _
.Columns(1).Column).Value = Result
End With
End Sub



"Bob Stearns" wrote:

I would like to come up with a macro to concatenate a range of cells like
A1:B3 into cell A4 (first row of range, last column of range plus one). I
would like to add a carriage return after concatenating each row. So in
this example A4 would be equal to =CONCATENATE(A1,A2,A3,CHAR(10),B1,B2,B3)

I would like to select the cells and then run the macro.

Any ideas would be greatly appreciated. Thanks...