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.
Related
I have excel sheet containing column with values such as
BANDHANBNK
SRF
SRTRANSFIN
L&TFH
IBULHSGFIN
FEDERALBNK
PNB
PEL
VOLTAS
I want to create hyperlink for each of this, url can be created as
https://in.tradingview.com/chart/?symbol=NSE:ACC1!
so I need to concatenate
https://in.tradingview.com/chart/?symbol=NSE: + cell value + 1!
doing this manually is too much work, is there any simpler way to do this?
one more thing is if cell value contains & or - it should be converted to underscore.
Use following formula. Here simply concatenating cell value with URL then concatenate 1!. Use Hyperlink() formula to make hyperlink.
=HYPERLINK("https://in.tradingview.com/chart/?symbol=NSE:" & A1 & "1!",A1)
To replace & and - by underscore _ use below SUBSTITUTE() formula.
=SUBSTITUTE(SUBSTITUTE(A1,"&","_"),"-","_")
this worked for me.
=HYPERLINK("https://in.tradingview.com/chart/?symbol=NSE:" & SUBSTITUTE(SUBSTITUTE(E2,"&","_"),"-","_") & "1!",E2)
Counting the number of superstrings within a range contain a substring is easy in LibreOffice Calc and Excel. How to count how many times a superstring contains substrings within a range? In the example below, the times an Animal is contained in a set is COUNTIF($A$2:$A$5,""&B2&"") for Dog, COUNTIF($A$2:$A$5,""&B3&"") for Cat and so on. How do I count how many Animals of range B:B are contained in "Cat Dog Mouse Snake"? The answers on column D should be 3, 1, 1, 1.
Place the following formula in D2. It is an array formula so you will need to use Control+Shift+Enter instead of just Enter. You will know you have done it right when { } show up around the formula in the formula bar. Note these cannot be added manually.
=SUM(--NOT(ISERR(SEARCH($B$2:$B$5,A2))))
Copy the cell and then paste in D3:D5.
First put this UDF in a standard module:
Public Function KeyKount(s As String, keywds As Range) As Long
Dim temp As String, cell As Range
KeyKount = 0
temp = " " & s & " "
For Each cell In keywds
v = " " & cell.Text & " "
If InStr(temp, v) > 0 Then KeyKount = KeyKount + 1
Next cell
End Function
Then in a cell enter, for example:
=keykount(A2,B2:B10)
Either:
=SUMPRODUCT(--(ISNUMBER(MATCH(FILTERXML("<a><b>"&SUBSTITUTE(A2," ","</b><b>")&"</b></a>","//b"),B:B,0))))
Or
=SUMPRODUCT(--ISNUMBER(SEARCH(" "&$B$2:$B$5&" "," "&A2&" ")))
Again both work in Excel, not sure about librecalc. The first will do fewer interactions if the string has less words than the lookup list, while the second is the opposite
For LO Calc:
=SUMPRODUCT(ISNUMBER(SEARCH(B$2:B$5;A2)))
I have excel file with version number column. The content of the column is for example: 70001, 70002.
What I want to do is to create another column refer to that column, and have the value to be 7.0.0.0.1, 7.0.0.0.2.
Any idea how to do it in excel?
If your values are in the column A you can use the following formula in the next column:
=MID(A1;1;1)&"."&MID(A1;2;1)&"."&MID(A1;3;1)&"."&MID(A1;4;1)&"."&MID(A1;5;1)
Assuming the value is in cell A2, use the formula:
=MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(
SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(
A2,"0",".0"),"1",".1"),"2",".2"),"3",".3"),"4",".4"),"5",".5"),"6",".6"),"7",".7"),
"8",".8"),"9",".9"),2,50)
which does a text replace for every single digit 1-9 with period plus digit, and at the end removes the first period by taking the substring from the second char.
Sorry.
The easiest way I can think of is to copy the cell, and then split it using Data | Text to Columns (fixed width, 1 line per character). Now concatenate the whole thing in another column using "." in the middle of each reference.
E.g.
=a1 & "." & b1 & "." & c1
etc
If you don't know about the length of the string, or if it varies, then you can use the below VBA function. It uses a FOR loop and take out each character and add a . to the end excepts last character. And at last concatenate the last character.
VBA function
Function version(str As Variant) As Variant
Dim l As Integer
l = Len(str)
For i = 1 To l - 1
version = version & Mid(str, i, 1) & "."
Next i
version = version & Right(str, 1)
End Function
Then use this function like, =version(A1)
If you have Excel 2016 with the CONCAT function, you can use the array formula:
=CONCAT(LEFT(A1),"." &MID(A1,ROW(INDIRECT("2:"&LEN(A1))),1))
This is an array formula and must be entered by holding down ctrl+shift while hitting Enter
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.
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).
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.
E.g
A1:I
A2:am
A3:a
A4:boy
I want to merge them all to a single cell "Iamaboy"
This example shows 4 cells merge into 1 cell however I have many cells (more than 100), I can't type them one by one using A1 & A2 & A3 & A4 what can I do?
If you prefer to do this without VBA, you can try the following:
Have your data in cells A1:A999 (or such)
Set cell B1 to "=A1"
Set cell B2 to "=B1&A2"
Copy cell B2 all the way down to B999 (e.g. by copying B2, selecting cells B3:B99 and pasting)
Cell B999 will now contain the concatenated text string you are looking for.
I present to you my ConcatenateRange VBA function (thanks Jean for the naming advice!) . It will take a range of cells (any dimension, any direction, etc.) and merge them together into a single string. As an optional third parameter, you can add a seperator (like a space, or commas sererated).
In this case, you'd write this to use it:
=ConcatenateRange(A1:A4)
Function ConcatenateRange(ByVal cell_range As range, _
Optional ByVal separator As String) As String
Dim newString As String
Dim cell As Variant
For Each cell in cell_range
If Len(cell) <> 0 Then
newString = newString & (separator & cell)
End if
Next
If Len(newString) <> 0 Then
newString = Right$(newString, (Len(newString) - Len(separator)))
End If
ConcatenateRange = newString
End Function
Inside CONCATENATE you can use TRANSPOSE if you expand it (F9) then remove the surrounding {}brackets like this recommends
=CONCATENATE(TRANSPOSE(B2:B19))
Becomes
=CONCATENATE("Oh ","combining ", "a " ...)
You may need to add your own separator on the end, say create a column C and transpose that column.
=B1&" "
=B2&" "
=B3&" "
In simple cases you can use next method which doesn`t require you to create a function or to copy code to several cells:
In any cell write next code
=Transpose(A1:A9)
Where A1:A9 are cells you would like to merge.
Without leaving the cell press F9
After that, the cell will contain the string:
={A1,A2,A3,A4,A5,A6,A7,A8,A9}
Source: http://www.get-digital-help.com/2011/02/09/concatenate-a-cell-range-without-vba-in-excel/
Update: One part can be ambiguous. Without leaving the cell means having your cell in editor mode. Alternatevly you can press F9 while are in cell editor panel (normaly it can be found above the spreadsheet)
Use VBA's already existing Join function. VBA functions aren't exposed in Excel, so I wrap Join in a user-defined function that exposes its functionality. The simplest form is:
Function JoinXL(arr As Variant, Optional delimiter As String = " ")
'arr must be a one-dimensional array.
JoinXL = Join(arr, delimiter)
End Function
Example usage:
=JoinXL(TRANSPOSE(A1:A4)," ")
entered as an array formula (using Ctrl-Shift-Enter).
Now, JoinXL accepts only one-dimensional arrays as input. In Excel, ranges return two-dimensional arrays. In the above example, TRANSPOSE converts the 4×1 two-dimensional array into a 4-element one-dimensional array (this is the documented behaviour of TRANSPOSE when it is fed with a single-column two-dimensional array).
For a horizontal range, you would have to do a double TRANSPOSE:
=JoinXL(TRANSPOSE(TRANSPOSE(A1:D1)))
The inner TRANSPOSE converts the 1×4 two-dimensional array into a 4×1 two-dimensional array, which the outer TRANSPOSE then converts into the expected 4-element one-dimensional array.
This usage of TRANSPOSE is a well-known way of converting 2D arrays into 1D arrays in Excel, but it looks terrible. A more elegant solution would be to hide this away in the JoinXL VBA function.
For those who have Excel 2016 (and I suppose next versions), there is now directly the CONCAT function, which will replace the CONCATENATE function.
So the correct way to do it in Excel 2016 is :
=CONCAT(A1:A4)
which will produce :
Iamaboy
For users of olders versions of Excel, the other answers are relevant.
For Excel 2011 on Mac it's different. I did it as a three step process.
Create a column of values in column A.
In column B, to the right of the first cell, create a rule that uses the concatenate function on the column value and ",". For example, assuming A1 is the first row, the formula for B1 is =B1. For the next row to row N, the formula is =Concatenate(",",A2). You end up with:
QA
,Sekuli
,Testing
,Applitools
,Visual Testing
,Test Automation
,Selenium
In column C create a formula that concatenates all previous values. Because it is additive you will get all at the end. The formula for cell C1 is =B1. For all other rows to N, the formula is =Concatenate(C1,B2). And you get:
QA,Sekuli
QA,Sekuli,Testing
QA,Sekuli,Testing,Applitools
QA,Sekuli,Testing,Applitools,Visual Testing
QA,Sekuli,Testing,Applitools,Visual Testing,Test Automation
QA,Sekuli,Testing,Applitools,Visual Testing,Test Automation,Selenium
The last cell of the list will be what you want. This is compatible with Excel on Windows or Mac.
I use the CONCATENATE method to take the values of a column and wrap quotes around them with columns in between in order to quickly populate the WHERE IN () clause of a SQL statement.
I always just type =CONCATENATE("'",B2,"'",",") and then select that and drag it down, which creates =CONCATENATE("'",B3,"'",","), =CONCATENATE("'",B4,"'",","), etc. then highlight that whole column, copy paste to a plain text editor and paste back if needed, thus stripping the row separation. It works, but again, just as a one time deal, this is not a good solution for someone who needs this all the time.
I know this is really a really old question, but I was trying to do the same thing and I stumbled upon a new formula in excel called "TEXTJOIN".
For the question, the following formula solves the problem
=TEXTJOIN("",TRUE,(a1:a4))
The signature of "TEXTJOIN" is explained as TEXTJOIN(delimiter,ignore_empty,text1,[text2],[text3],...)
I needed a general purpose Concatenate With Separator (since I don't have TEXTJOIN) so I wrote this:
Public Function ConcatWS(separator As String, ParamArray cell_range()) As String
'---concatenate with seperator
For n = LBound(cell_range) To UBound(cell_range)
For Each cell In cell_range(n)
If Len(cell) <> 0 Then
ConcatWS = ConcatWS & IIf(ConcatWS <> "", separator, "") & cell
End If
Next
Next n
End Function
Which allows us to go crazy with flexibility in including cell ranges:
=ConcatWS(" ", Fields, E1:G2, L6:M9, O6)
NOTE: "Fields" is a Named Range and the separator may be blank