Frage

I am trying to combine sentences from various cells into one cell. Example:

A1 - "hello"
A2 - "how are"
A3 - "you"

A4 - =combine(A1:A3) ---- > "hello how are you"

I know this trick: =A1 & " " & A2..... but I have 700 cells to combine into a single cell and this approach seems barbaric. If there is a built in function, that would be ideal. I don't mind an answer in VBA as long as the answer is extremely detailed starting with how to open VBA, as I do not know VBA.

War es hilfreich?

Lösung

There is but it isn't much better: concatenate.

In your case, that would be concatenate(A1;" ";A2;" ";A3).

Neither are good ways to deal with 700 cells.

A VBA solution would be better. To open the VBA editor, press ALT+F11 (for a graphical explanation, see this article).

Afterwards, go to the "Insert" menu on top and select "Module". The editor will then be ready to accept input. Just paste the following (delete any other text that it may have):

Option Explicit

Public Function MyConcatenate(ByVal myRange As Range)
    Dim vCell, vResult As String
    For Each vCell In myRange.Cells
        vResult = vResult & " " & vCell.Text
    Next
    MyConcatenate = Mid(vResult, 2)
End Function

You can now close the editor and return to the workbook.

To use it, write the following in a cell: =MyConcatenate(A1:A3).

Andere Tipps

You can use the StringConcat function found in this page: http://www.cpearson.com/excel/stringconcatenation.aspx

Then you can use it like this:

=StringConcat("|",B1:B5)

An you will received all values from the range: B1:B5 separated by |.

In case the link is broken, you can find the source of the function here: http://pastebin.com/JNS9pYWA.

For a relatively modest 700 cells formulae would seem viable.

in B1: =A1&" "
in C1: =B1
in B2: copy B1 (ie =A2&" ")
in C2: =C1&B2

then copy down B2:C2 as required.

I too have the same problem. I have data in column A from A1:A980. But I have found out the solution as below.

In B2 I put the formula as =CONCATENATE(B1," ",A1," ",A2) and from B3 I entered formula as =CONCATENATE(B2," ",A3) and in B3 as =CONCATENATE(B3," ",A4) till B980.

This will give you your result in last B90 cell and that too without any VBA.

Hope you might have the same problem then this might solve the issue.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top