How can I concat cellvalues with new line in MS Excel? - excel

In excel I can introduce a new line inside a cell with a [alt enter]
Boo[alt enter]Far
results in:
Boo
Far
Now A1 contains Boo, A2 contains Far. How can I display these values in A3 separated with a new line?
A3=A1[alt enter]&B1
results in BooFar
A3=A1&[alt enter]B1
results in BooFar
How can I get
Boo
Far
By using cell references?

In A3 enter:
=A1 & CHAR(10) & A2
and format A3 for wrap text

If it helps anyone using Office on Mac, you should use CHAR(13) for line breaks.
For the above example, that would be
=CONCATENATE(A1, CHAR(13), A2)
And of course, format for wrap text.
The 10 and 13 represent Line Feed & Carriage Return characters.

Related

Looking for a way to split cells in excel based the last five numbers in a cell

I am looking for a way to fix a mixed data set representing addresses in Excel.
Here is an example dataset.
Kirchgasse 2389179 Beimerstetten
All this should result in three datasets.
A1 = Kirchgasse 2389179 Beimerstetten
A2 = Kirchgasse 23
A3 = 89179
A4 = Beimerstetten
Pattern is, that A3 is always the last 5 numbers in the dataset.
I am totally lost here, as Excel is usually not my weapon of choice.
You can use Excel Formulas as well, to split cells, Excel gives us ample opportunity to use the features, there are lot of ways for a query to resolve, you can follow any of the following approaches, to accomplish the desired output
To Extract The First Part From Cell A1, Formula Used In Cell A2
=LEFT($A1,FIND(" ",$A1)+2)
To Extract The Second Part From Cell A1, Formula Used In Cell A3
=LEFT(REPLACE($A1,1,LEN($A2),""),5)
To Extract The Last Part Of The String From Cell A1, Formula Used In Cell A4
=TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",100)),100))
However To Extract The 5 Numbers, you can use any one of the following as well that suits with your Excel Version
Formula shown in cell A11
=MAX(IFERROR(MID($A$1,ROW(INDIRECT("1:"&LEN($A$1))),5)*1,""))
Formula shown in cell A13
=LARGE(IFERROR(--MID($A1,SEQUENCE(LEN($A1)),COLUMN($A$1:$E$1)),0),1)
Formula shown in cell A15
=AGGREGATE(14,6,IFERROR(--MID($A1,ROW($1:$10000),COLUMN($A$1:$E$1)),0),1)
Formula shown in cell A17
=--RIGHT(FILTERXML("<p><w>"&SUBSTITUTE($A1," ","</w><w>")&"</w></p>","//w[.*0=0]"),5)
To get a detailed knowledge on FILTERXML Function you can refer the link below, prepared by JvdV Sir
FILTERXML FUNCTION DETAILED ANALYSIS BY JvdV Sir
Here is few more ways
Formula used in cell A2
=SUBSTITUTE(TRIM(FILTERXML("<p><w>"&SUBSTITUTE(SUBSTITUTE(LEFT($A1,FIND(" ",$A1)+2)&REPLACE($A1,1,FIND(" ",$A1)+2," ")," ","#",1)," ","</w><w>")&"</w></p>","//w")),"#"," ")
Just enter the formula in cell A2, and it will spill if you are using O365 or Excel 2021
And if you are not using the above Excel Version then you may try this and Fill Down The Formula
Formula Used In Cell B2 & Fill Down
=SUBSTITUTE(TRIM(FILTERXML("<p><w>"&SUBSTITUTE(SUBSTITUTE(LEFT($A$1,FIND(" ",$A$1)+2)&REPLACE($A$1,1,FIND(" ",$A$1)+2," ")," ","#",1)," ","</w><w>")&"</w></p>","//w["&ROW(A1)&"]")),"#"," ")
In A2, formula copied down :
=TRIM(SUBSTITUTE(MID(SUBSTITUTE(" "&REPLACE(REPLACE(A$1,AGGREGATE(14,6,FIND(ROW($1:$10)-1,A$1,COLUMN(A:Z)),1)-4,0," "),FIND(" ",A$1),1,"#")," ",REPT(" ",50)),ROW($A1)*50,50),"#"," "))
Put Kirchgasse 2389179 Beimerstetten in the A1 cell, and use the below VBA codes to set the D1 cell value as the last 5 numbers
Sub Test_Pattern()
Dim stringOne As String
Dim regexOne As Object
Set regexOne = New RegExp
regexOne.Pattern = "(\d{5})(?!.*\d)"
regexOne.Global = TRUE
regexOne.IgnoreCase = IgnoreCase
stringOne = Range("A1").Value
Set theMatches = regexOne.Execute(stringOne)
For Each Match In theMatches
Range("D1").Value = Match.Value
Next
End Sub
To learn how to use regex in VBA, see this ref

Excel text to rows using formula

I have a concat formula returning me a comma separated list of names in a cell
=concat(A2:A10 & " ,") returning [john, jack, jill] in the cell
Is there a way to add to this formula to expand to
john
jack
jill
in a column like that above?
You can change the separator to be a line break =CONCAT(A2:A10 & CHAR(10)) or =TEXTJOIN(CHAR(10),TRUE,P3:P5)
The target cell needs to be set to Wrap Text for the line breaks to be displayed correctly.
I used Power Editor to convert the cell into rows

excel function to combine cells into single line of text?

I'm new to stack overflow so I apologize if this is a horrendously stupid question. I am wondering if there is a function or way to code a function in excel that will combine a column of cells with plain text and convert them into one cell with the text on a single line? Specifically I want to convert a column of random numbers into a single line of text and insert SPACE+AND+SPACE between them.
Ex.
15133484
12345188
12345888
to
15133484 AND 12345188 AND 12345888
Currently I am copying and pasting all this information into google and then into Word and using find/replace and it is taking forever everytime. If it is possible to just get Excel to do this for me that would be amazing.
Thanks!
If you have Office 365 Excel use TEXTJOIN():
=TEXTJOIN(" AND ",TRUE,A:A)
otherwise one would have to use:
=A1 & " AND " & A2 & " AND " & A3
Or one can use a helper column, B1 put:
=A1
put this in B2 and copy down:
=IF(A2<>"",B1 & " AND " & A2,B1)
And grab the last cell in column B.
A little late, but still:
Reference here
Step 1:
=concatenate(transpose(rngBeg:rngEnd & " AND "))
Step 2:
highlight the transpose statement and then press F9, which substitutes the actual values for the formula.
Step 3:
Remove the curly braces, { }, from the formula. The cell will display the range of reference cells combined with whatever separator chosen after the ampersand sign.
Not a "live" formula, but still far easier than manually concatenating a range of values.
Press ALT+F11 to open Microsoft Visual Basic for Applications,
Insert-> Module
Paste this:
Function Combine(WorkRng As Range, Optional Sign As String = " AND ") As String
Dim Rng As Range
Dim OutStr As String
For Each Rng In WorkRng
If Rng.Text <> "," Then
OutStr = OutStr & Rng.Text & Sign
End If
Next
Combine = Left(OutStr, Len(OutStr) - 5)
End Function
In any cell type =Combine(Range)
i.e.
=Combine(A1:A500)
use concat function if you can add an additional column in the excel like this:
=CONCAT(D3:E5)
Attached sample image with input, additional column, output and formula
I assume you want to merge the data in the 3 cells into a single cell with a space between the 3 data set.
If that is the case then you can do it simply by using the Concatenate function in excel.
In the above example, you have data in Cells A1, A2 & A3.
Cell C1 has the merged data. As you can see, we have used CONCATENATE Function.
The space has been defined in Double quotes. So if you need a Hyphen (-), you can put that in Double Quotes with space “ - ” and it will display the result with Sanjay - Singh - Question
Hope this helps.

Referencing a cell to have a line change

In excel, it is possible to force a line change in the cell by pressing alt+enter when typing. Say I have cell A1 with "abc" on the top and "def" on the next line.
I want to write "=A1" in the cell A2 so that it displays the same thing. Unfortunately, they get concatenated, and in A2 it is simply written abcdef.
Does anyone know if it is even possible to do?
writing
="abc" & vbLF & "def"
does not work. Neither does chr(10). I can do it with vba but I would rather have a simple reference.
A copy/paste of A1 does not work either, as it splits the text between the cells underneath it. (A2 contains "abc", and A3 contains "def")
If you select the cell with the formula and hit "Wrap Text" the line breaks will appear as they were in the referenced cell.
For those that don't know where wrap text is at it is under the "Home" Tab in the "Alignment" category: (for excel 2010)

Excel merging two rows into one

May I know how to merge two data into one cell?
For example:
A1 - 100100
A2 - 110000
into
A3 - 100100
110000
Just concatenate them as you normally would, and a line feed (char(10)) in the middle:
=A1 & CHAR(10) & B1
Make sure that "Wrap text" is set for cell A3.
or alternately:
=CONCATENATE(A1; CHAR(10);A2)
you'll still need the Wrap text enabled.
good page to learn more about excel functionality like this
http://www.excelfunctions.net/excel-string-concatenation.html

Resources