View Single Post
  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

Hari,

I had a similar need once so I wrote a macro to do it. Just select the first
cell in the row, and run the macro, it concatenates it all into that active
cell

Sub JoinData()
Dim cLastCol As Long
Dim cell As Range
With ActiveCell
cLastCol = Cells(.Row, Columns.Count).End(xlToLeft).Column
For Each cell In Range(ActiveCell, Cells(.Row, cLastCol))
.Value = .Value & " " & cell.Value
Next cell
End With
End Sub

If you want to clear out the other stuff

Sub JoinData()
Dim cLastCol As Long
Dim cell As Range
With ActiveCell
cLastCol = Cells(.Row, Columns.Count).End(xlToLeft).Column
For Each cell In Range(ActiveCell, Cells(.Row, cLastCol))
.Value = .Value & " " & cell.Value
Next cell
Range(.Offset(0, 1), Cells(.Row, cLastCol)).ClearContents
End With
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Hari" wrote in message
...
Hi,

Let's say I have text "we45t" in A1, "yuui6" in A2, "sfdgfd5" in A3 and so
on till A45. (basically the text in each of the columns are
different/random)

Now I have to concatenate all the cells from A1 to A45 (with a single

space
between any 2 joinees) in to a single cell B1.

I can get the job done by using
a) = Concatenate (A1," ",A2," ",A3," ",A4," ",A5," ",A6," ",.......) and

so
till A45
b) =A1&" "&A2&" "&A3&" "&A47" "&A5&" "&A6&" "&....... and so on till A45.

I'm tired of writing till A45, hence, did not write it out fully.

Is there any Excel formula / technique using by which one can specify only
the first cell (A1) and the last cell (A45 in this case) and get the
concatenate without pains.

(If you are curious as to what I do with the concatenation result...- I

use
excel for preparing job files for a Cross tabulation program, hence use
excel as an intermediary to simplify the process of making jobs)

Thanks a lot,
Hari
India