Split into columns using three different separators - excel

I want to convert an Excel field into three columns based on these three delimiters: forward slash, dash, and close parenthesis: ) / -
And here is what I need to see:
I've tried the 'Text to Columns' Data Tool in excel, but it cannot accept three custom separators at once.
I want a simple and fast Excel method that can convert the following pattern:

You can try FILTERXML/SUBSTITUTE:
=SUBSTITUTE(FILTERXML("<a><b>'" & SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A2,"/","</b><b>'"),")","</b><b>'"),"-","</b><b>'") & " </b></a>","//b[" & COLUMN(A:A) & "]"),"'","")

One approach is to first fix the data and then run TextToColumns. Select the cells you wish to process and run this short VBA macro:
Option Explicit
Sub FixPhoneData()
Dim cell As Range, v As String
For Each cell In Selection
With cell
v = .Value
v = Replace(v, ")", "-")
v = Replace(v, "/", "-")
.Value = v
End With
Next cell
End Sub
Before:
and after:

If one has Excel O365, you could try:
Formula in B1:
=TRANSPOSE(MID(CONCAT(IFERROR(MID(A1,SEQUENCE(LEN(A1)),1)*1,"")),{1,4,7},{3,3,4}))
Now you can throw any pattern at the formula as long as you provide the usual 10 digits.
If always these three same patterns, you could also use:
=TRANSPOSE(MID(RIGHT(A1,12),{1,5,9},{3,3,4}))
This last, simpler solution can also be used in Excel prior to O365 if one used INDEX():
=INDEX(MID(RIGHT($A1,12),{1,4,7},{3,3,4}),COLUMN(A1))
Drag this formula right, and down.
If your goal was to ultimately have this pattern in a single cell then things became much easier in an instant, and you can use:
=REPLACE(RIGHT(A1,12),4,1,"-")
If you need to do this in GS then try:
=SPLIT(REPLACE(RIGHT(A1,12),4,1,"-"),"-")

Related

Im trying to extract all the words in a single cell which contain following characters "ROWID" into other columns

For example, if i have a cell which contains
ADDR_ROWID,LOC_ROWID,ADDR_LINE_1,ADDR_LINE_2,CITY,ST_PROV,CNTRY_CODE,POSTAL_CODE,STAT_IND,ADDR_TYPE_ROWID in cell A1
i want to extract ADDR_ROWID in B1, LOC_ROWID in C1 and ADDR_TYPE_ROWID in D1 cells respectively. is there any way possibly doing it?
Try FILTERXML():
Formula in B1:
=TRANSPOSE(FILTERXML("<t><s>"&SUBSTITUTE(A1,",","</s><s>")&"</s></t>","//s[substring(., string-length(.)-5) = '_ROWID']"))
We basically created the missing ends-with() xpath function. See here for a more in-depth explaination why this works.
Or; with the newest versions of Excel you can even use:
=LET(X,TEXTSPLIT(A1,","),FILTER(X,RIGHT(X,6)="_ROWID",""))
Note: The latter is currently case-insensitive where the FILTERXML() option is case-sensitive.
So a method with find(), iferror() and if(), perhaps simpler than some:
Formula in cell B1:
IF(IFERROR(FIND("ADDR_ROWID",A1,1),0)>0,"ADDR_ROWID","")
The others just change the text in the find() & if().
If you have access to VBA/Macros, then this snip-it might help;
Sub caller_getROWIDs()
GetROWIDs [A1], [B1]
End Sub
Sub GetROWIDs(rInput As Range, rOutput As Range)
For Each SubString In Split(rInput.Value, ",")
If InStr(SubString, "ROWID") Then
rOutput.Value2 = SubString
Set rOutput = rOutput.Offset(, 1)
End If
Next
End Sub
You can achive this with just excel formulas.
first you need to extract all the words in the cell which is separated by comma ",".
FORMULA 1.
=TRIM(MID(SUBSTITUTE(A1,",",REPT(" ",LEN(A1))),(SEQUENCE(,15)-SEQUENCE(,LEN(TRIM(A1))-LEN(SUBSTITUTE(TRIM(A1)," ",""))+1,1,1))*LEN(A1)+1,LEN(A1)))
Note: SEQUENCE(,15) is i am assuming there could be 15 word(I know there is 10 words since its only one cell imagine if you have more than 100), you can put any number as long as its not less then the actual word might be.
once you extract all the words from the cell then you need to filter your conditions which is if the letter contains "ROWID".
FORMULA 2.
=FILTER(TRIM(MID(SUBSTITUTE(A1,",",REPT(" ",LEN(A1))),(SEQUENCE(,15)-SEQUENCE(,LEN(TRIM(A1))-LEN(SUBSTITUTE(TRIM(A1)," ",""))+1,1,1))*LEN(A1)+1,LEN(A1))),ISNUMBER(SEARCH("ROWID",TRIM(MID(SUBSTITUTE(A1,",",REPT(" ",LEN(A1))),(SEQUENCE(,15)-SEQUENCE(,LEN(TRIM(A1))-LEN(SUBSTITUTE(TRIM(A1)," ",""))+1,1,1))*LEN(A1)+1,LEN(A1))))))
You can just use the formula 2.

How to extract middle characters from a cell in Excel

I need a excel function code that would enable to me extract certain characters in the middle of a cell.
So in cell A74 is:
1625362674848-cdpresent-auths_ol_mart-auths1837372
So I Need to extract "auths_ol_mart" into a separate column
I have tried this:
=MID(A2, SEARCH("-",A2) + 1, SEARCH("-",A2,SEARCH("-",A2)+1) - SEARCH("-",A2) - 1)
Now the problem is this only gets "cdpresent". I am not quite sure how this is done.
more examples include:
3837463747-cdpresent-avaya_op_history-clm1827489
I want "avaya_op_history"
3734279458-cdpresent-uk_score_app-clm9377233
I want "uk_score_app"
Thank you all
You can use this worksheet formula:
=LEFT(MID(A1,FIND("-",A1,FIND("-",A1)+1)+1,99),FIND("-",MID(A1,FIND("-",A1,FIND("-",A1)+1)+1,99))-1)
If you use the Formula Evaluation tool, you will be able to see how this works.
If you prefer a UDF, you can use:
Function betweenDashes(S As String) As String
betweenDashes = Split(S, "-")(2)
End Function
Edit (20MAR2020)
Another formula to return the third item in the string, if you have Excel 2013+ and the FILTERXML function:
=FILTERXML("<t><s>" & SUBSTITUTE(A1,"-","</s><s>")& "</s></t>","//s[3]")
or, if you prefer, the next to last item:
=FILTERXML("<t><s>" & SUBSTITUTE(A1,"-","</s><s>")& "</s></t>","//s[last()-1]")
An alternative way to formula is Text to Columns with hyphen (-) as a delimiter. You get what you are looking for in the 3rd column:

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.

Delete from a String: All Words that Appear in a Column in Excel

I've found workarounds for this problem - but I'm having a hard time imagining there isn't a simpler solution than what I have.
Let's Suppose in Column A, I have cells with the following words in them...
A1: Until
A2: I
A3: The
A4: Have
And in cell B1, I have this sentence:
"Until further notice, I have closed the Icecream store"
In cell C1, I want it to return:
"Further Notice, Closed Icecream Store"
Currently, I've been using the =SUBSTITUTE() function over and over like this:
=PROPER(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B1, $A$1, ""), $A$2, ""),$A$3, ""), $A$4, ""))
However with that formula, the "I" in "Icecream" will be deleted, and the formula itself will have to become ridiculously long in order to accommodate hundreds of cells in Column A.
Another option I've found that is equally as clunky is to use the =SPLIT() function on cell B1 to separate each word of the string into it's own cell (cells C1:Z1), then using:
=IF(ISNUMBER(SEARCH(C1,$A$1:$A,1)),"",C1)
=IF(ISNUMBER(SEARCH(D1,$A$1:$A,1)),"",D1)
etc...
In cells AA1:AZ1 to delete the unwanted words. And then finally in Cell BA1, a =CONCATENATE() formula to put all the cells back together into the desired string. This formula will also have issues with the "I" in "Icecream", so the only workaround for that I've found is putting spaces before and after each word in Column A, and adding spaces before and after the string in B1.
I'm curious if there's a better way to approach this problem that doesn't either require writing an essay long formula, or using thousands of cells and formulas to separate each word and check individually.
Thanks!
Tyler
With the Google Sheets REGEXREPLACE and JOIN Functions, sample regular expression can be:
(?i)\b(Until|I|Have|The)\b
where (?i) is an ignore case flag, \b is word boundary, and () is a capturing group.
=PROPER(TRIM(REGEXREPLACE(B1, "(?i)\b(" & JOIN("|", A1:A4) & ")\b", "")))
The Trim function also removes extra spaces between words.
Excel 2016 has TextJoin Function, but no RegEx Functions yet (VBA UDF can be used instead).
Microsoft Word has similar but limited pattern matching using wildcards, but joining the pattern in Word would be too challenging. Sample wildcards replace pattern in Word : <(Until|I|Have|The)>
Consider the following UDF():
Public Function NoJunk(r1 As Range, r2 As Range) As String
Dim ary(), r As Range
temp = " " & r1.Text & " "
ReDim ary(1 To r2.Count)
i = 1
For Each r In r2
ary(i) = " " & r.Text & " "
i = i + 1
Next r
For i = 1 To r2.Count
temp = Replace(temp, ary(i), " ")
Next i
NoJunk = Application.WorksheetFunction.Trim(temp)
End Function
For example:
Because the comparisons are case sensitive, I have included both lower case and proper case in column A.
User Defined Functions (UDFs) are very easy to install and use:
ALT-F11 brings up the VBE window
ALT-I
ALT-M opens a fresh module
paste the stuff in and close the VBE window
If you save the workbook, the UDF will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the UDF:
bring up the VBE window as above
clear the code out
close the VBE window
To use the UDF from Excel:
=nojunk(B1,A1:A8)
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
and for specifics on UDFs, see:
http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx
Macros must be enabled for this to work!
If it is less then ~10 or so unique words which you know what is to be deleted, you could just copy the column, Ctrl + H and Find/Replace that word with nothing and repeat until you've removed them all.

How to merge rows in a column into one cell in excel?

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

Resources