Splitting two words in excel - excel

Spliiting Words together in a pair like (Head LM) from other word in a cell in Excel
Name Role
John Dowe (Head LM); Moniq Jamese (Lead JK); Larrye Stuarte (Front TR) John Dowe Head LM
I need to be able to split [Head LM] from the rest of the text without the parentesis, just Head LM. I tried several options like:
=TRIM(RIGHT(SUBSTITUTE(S3," ",REPT(" ",100)),300))
=RIGHT(S3, LEN(S3)-FIND(" ", S3,1)-5) =>resule is : (Lead PM); J
In both instances the text isn't clean from the () and other words.

if A1 contains:-
John Dowe (Head LM); Moniq Jamese (Lead JK); Larrye Stuarte (Front TR)
This:-
=LEFT(MID(A1,FIND("(",A1)+1,LEN(A1)),FIND(")",MID(A1,FIND("(",A1)+1,LEN(A1)))-1)
returns:-
Head LM
For clarification:-
MID(A1,FIND("(",A1)+1,LEN(A1)) finds the part of A1 that starts after the first (
FIND(")",MID(A1,FIND("(",A1)+1,LEN(A1))) works out the number of characters to the second )
LEFT({...first snippet...},{...second snippet...}-1) trims off the second )
Update to handle all names/titles
A1 your example text
B1 =LEFT(A1,FIND(";",A1))
C1 =LEFT(B1,FIND(" (",B1)-1)
D1 =MID(B1,FIND("(",B1)+1,FIND(")",B1)-(FIND("(",B1)+1))
E1 =MID(A1,LEN(B1)+2,FIND(";",A1)+3)
F1 =LEFT(E1,FIND(" (",E1)-1)
G1 =MID(E1,FIND("(",E1)+1,FIND(")",E1)-(FIND("(",E1)+1))
H1 =MID(A1,LEN(B1)+2+LEN(E1)+1,LEN(A1))
I1 =LEFT(H1,FIND(" (",H1)-1)
J1 =MID(H1,FIND("(",H1)+1,FIND(")",H1)-(FIND("(",H1)+1))
B1 pulls the first name block (up to the first semi-colon)
E1 pulls the second name block (up to the second semi-colon)
H1 pulls the third name block
C1, F1, I1 pull the name from their respective block
D1,G1,J1 pull the title from their respective block
Any columns that are not required can be hidden - leaving just the required ones visible. Breaking out the three blocks into B1, E1 and H1 make the formulae in the other cells simpler - but could be avoided, by substituting (for example) the formula in B1 wherever B1 appears in the other formulae (though this, obviously, makes those formulae even more complex). This would then remove the need to hide any unwanted columns - as you would only calculate the values you require.

This assumes that you want to get ALL of the words in parentheses, not just the first occurrence (this was not really clear in your question, so I assumed you were interested in all of them). To do this, you'll need to split that cell using Text-To-Columns or something of that nature, so that your formula only has to deal with one name/title at a time. Then copy/transpose it so that each name/title is in its own row.
That done, you can use a formula like:
=SUBSTITUTE(SUBSTITUTE(RIGHT(A1,LEN(A1)-FIND("(",A1,1)+1),"(",""),")","")
Here is a picture:
If you don't need ALL of the titles in parentheses, then you could obtain only the first instance without doing any Text-to-Columns/additional steps/etc. as per #dav1dsm1th's answer.

Split this into a number of smaller problems so it makes sense.
To find the beginning of the word, first find the open paren
=FIND( "(", A1 )
To find the end of the word, find the close paren that follows your open paren
=FIND( ")", A1, FIND( "(", A1) )
So with these worked out, you can find your word. It starts 1 character after the open paren and goes for the length between the two minus that 1 character.
= MID( A1, FIND( "(", A1 ) + 1 , ( FIND( ")", A1, FIND( "(", A1) ) - FIND( "(", A1 ) ) - 1 )

Related

Splitting delimitted column using ONLY formula

There are similar requests, but not quite what i'm after. Take this example value:
aa;bb;cc;dd
The values between each semi-colon aren't fixed. They range from 3-15 characters. I need to pull the substring out from between the semi-colons.
I've got 'aa' and 'bb' sorted, but i'm struggling with 'cc' onwards. Here are my first two formulae:
=LEFT(A1,FIND(";",A1)-1)
...get values to the left of the first semi-colon
=MID(A1,
(FIND(";",A1)+1),
FIND(";", A1, (FIND(";",A1) + 1))-(FIND(";", A1) + 1))
...get values between the first and second semi-colon. Stuck at the third (wish I could use variables.. JSON perhaps?)
The end goal is to split out a multi-choice column into 5 columns for Power BI reporting. We want all of the computation done and dusted before it hits the report; I know there is a split on delimiter option in Power BI.
Any assistance would be much appreciated, thanks.
P.S. Tagged in Excel since Sharepoint apparently uses the same formulas, and that's what i'm testing in at the moment.
I can't assure you to work it in sharepoint but it will work on excel. Try below formula.
=TRIM(RIGHT(LEFT(SUBSTITUTE($A1,";",REPT(" ",100)),COLUMNS($A$1:A1)*100),100))
As per below screenshot, put the formula in B1 cell then drag to right as needed.
There are dozens of ways of doing it just with formulas. Without going to anything too esoteric and without resorting to array formulas you could use something like:
=TRIM(MID(SUBSTITUTE($A3,";",REPT(" ",LEN($A3))),(COLUMN(F:F)-2)*LEN($A3)+1,LEN($A3)))
Try this:
Create a header row where your fields will be split out to, numbered from 1 to 5 (in cells B1 - F1). These #s will be used in the formula.
The 2nd row will have the start of your data (in cell A2). In cell B2, enter this formula:
=TRIM(MID(SUBSTITUTE($A2,";",REPT(" ",LEN($A2))),(B$1-1)*LEN($A2)+1,LEN($A2)))
Then you can use the fill handle (+) to copy it across from B2 to F2.
Reference: https://exceljet.net/formula/split-text-with-delimiter
Beautified version of the formula:
=TRIM(
MID(
SUBSTITUTE(
$A2,
";",
REPT(
" ",
LEN(
$A2
)
)
),
( B$1 - 1 ) *
LEN(
$A2
) + 1,
LEN(
$A2
)
)
)
And for 1-time interactive passes, you can use Excel's built-in delimiting: Go to Data -> Text to Columns and walk through the wizard.

Excel - extracting text between parentheses after finding certain text

I have tried searching for an answer but can't seem to find the exact solution. I am trying to extract text between two parentheses starting at a certain string of text. I.e. the cell contains the following – ABC (12.3%) DEFGH (18.1%) IJKL (17.2%). I want to have a reference cell saying "ABC" then the cell below return the % number in between parentheses following ABC.
The current formula I am using is the below, where G6 is the full line of text and I5 is the reference cell "ABC":
=MID(G6,FIND(I5,G6)+FIND("(",G6),FIND("(",G6)+1+FIND(")",G6)-FIND("(",G6)-7)
This will work when the Input is 3 characters long (ABC), but won't work when the string text is a different length.
Can someone help me create a formula where I can pull the % number regardless of how many characters there are?
With the big string in A1 and ABC in B1, try:
=LEFT(MID(A1,FIND(B1,A1)+LEN(B1)+2,9999),FIND(")",MID(A1,FIND(B1,A1)+LEN(B1)+2,9999))-1)
what is going on:
The core of the formula: MID(D1,FIND(E1,D1)+LEN(E1)+2,9999) discards the front end of the string and returns:12.3%) DEFGH (18.1%) IJKL (17.2%).The enclosing part discards the closing parens and every that follows.
If you are trying to separate all the different strings, then it might be best to split it up.
String Splitting
Cell A1: 'The current String'
Cell B1: =SEARCH("(",A2)
Cell C1: =SEARCH(")",A2)
Cell D1: =MID($A$2,1,B2-1)
Cell E1: =MID($A$2,B2+1,(C2-B2)-1)
Cell F1: =SEARCH("(",A2,12)
Cell G1: =SEARCH(")",A2,12)
Cell H1: =MID($A$2,C2+1,(F2-C2)-1)
Cell I1: =MID($A$2,F2+1,(G2-F2)-1)
Cell J1: =SEARCH("(",A2,26)
Cell K1: =SEARCH(")",A2,26)
Cell L1: =MID($A$2,G2+1,(J2-G2)-1)
Cell M1: =MID($A$2,J2+1,(K2-J2)-1)
B1 & C1 will search for the first appearance of "(" & ")".
D1 & E1 will then use those numbers in B1 & C1 to find the text you're searching for.
F1 & G1 will search for the second appearance of "(" & ")"
H1 & I1 will then use those numbers in F1 & G1 to find the text you're searching for.
J1 & K1 will search for the third appearance of "(" & ")"
L1 & M1 will then use those numbers in J1 & K1 to find the text you're searching for.
This process breaks it down for every piece of string. In the picture I attached I also added additional fields for trimming the results to eliminate any blank spaces.

How do I select just some data from a cell with multiple values?

I have a CSV file imported into Excel 2010. One cell contains a portion of text that I want, but it is of different lengths and locations within the cell. Not every record has data in the cell. Each piece of text is delimited by a semicolon (;) but still within the same cell. So:
B2 = text_I_want
B3 = blank
B4 = text_I_don't_want; text_I_want_that_has_a_different_length; more_text_I_don't_want
B5 = text_I_don't_want; text_I_don't_want; text_I_don't_want; text_I_want_now;
Column M of the same row should contain the entire text I want but only what I want. So:
M2 = text_I_want
M3 = blank
M4 = text_I_want_that_has_a_different_length
M5 = text_I_want_now
There are more than 10,000 records to go through and would appreciate help.
EDIT: I didn't explain myself clearly. Column B contains a string of text which contains various hyperlinks. Each cell could contain zero hyperlinks, one hyperlink, 2, 3, 4 and so on. Each hyperlink is separated by a semicolon. I want only the amazon.com hyperlinks, not the amazon.ca or amazon.co.uk or any other hyperlinks. I hope this is a clearer example, with what I want in a separate field, bolded.
-B2 = amazon.com/12345
-B3 =amazon.ca/search?keywords=William+Shatner
-B4 =amazon.ca/12AB; amazon.com/AB1; loc.gov/fubar
-B5 =amazon.com/978037346; amazon.de/search?VX123
 
EDIT #2 - Since I can convert the text to columns, how about this questions: how do I search a row com columns A-G for any cell containing amazon.com and then copy that cell contents into column M?
You can use Find/FindB (depending on whether your content is single byte or MBCS data - the ones ending in B are for MBCS data).
In N2, for instance, you can use
=Find(M2, B2)
N2 will contain the offset (index) of the text in M2 in B2, or zero if it's not found.
To extract the text, use Mid/MidB and Len/LenB. You can add this in P2, for example:
=IF(N2 > 0, MID(B2, N2, LEN(M2)), "")
This checks to see if the value in N2 is greater than zero, and if it is copies the text from B2 starting at the position indicated in N2 for the number of characters returned as the length of the text in M2. If N2 is zero, it returns a blank space.
You could, in fact, combine both operations into one (it's a little harder to read):
=IF(Find(M2, B2) > 0, Mid(B2, Find(M2, B2), Len(M2)), "")
Based on your first edit, with amazon.com/ in B1 (for the sake of flexibility) then:
=IF(AND(IFERROR(FIND(";",B2,IFERROR(FIND($B$1,B2),"")),"")="",IFERROR(FIND($B$1,B2),"")<>""),B2,IFERROR(MID(B2,IFERROR(FIND($B$1,B2),""),IFERROR(FIND(";",B2,IFERROR(FIND($B$1,B2),"")),"")-IFERROR(FIND($B$1,B2),"")),""))
(copied down as required) should work.

String Separate in Excel

mozilla-nss-3.11.4-0.7
gdb-10.12-1.5.2
glibc-dcc-atv-1.0.3-10.6
i want to separate it too in the next B C D cell
mozilla-nss 3.11.4 0.7
gdb 10.12 1.5.2
glibc-dcc-atv 1.0.3 10.6
right now i can use left , right and find function to do it but not quite work well
i use
LEFT(B33,FIND(".",B33)-2) =B cell
RIGHT(B33,FIND(".",B33)) =C Cell
RIGHT(D33,FIND("-",D33)-1) = D Cell
answer is not right anyone can Help me correct my function thank you
The key point here which makes the task difficult - we need to use as separators LAST TWO hyphens in the string, and remain all the rest intact. For such cases ARRAY formulas is the best shot. My solution is below:
Name 6 columns starting A1: String | MAX "-" | 2nd MAX "-" | Str1 | Str2 | Str3
Put your values in Column A starting at A2.
B2 (MAX "-"): type the formula =MAX(IFERROR(SEARCH("-",$A2,ROW(INDIRECT("1:"&LEN($A2)))),0)) but press CTRL+SHIFT+ENTER instead of usual ENTER - this will define an ARRAY formula and will result in {} brackets around it (but do NOT type them manually!).
C2 (2nd MAX "-"): type the formula =MAX(IFERROR(SEARCH("-",$A2,ROW(INDIRECT("1:"&LEN($A2)))),0)*IF(IFERROR(SEARCH("-",$A2,ROW(INDIRECT("1:"&LEN($A2)))),0)=MAX(IFERROR(SEARCH("-",$A2,ROW(INDIRECT("1:"&LEN($A2)))),0)),0,1)) and again press CTRL+SHIFT+ENTER.
Thus we'll obtain positions of LAST TWO hyphens in the string. The rest is easy - ordinary LEFT / MID / RIGHT stuff:
D2: =LEFT($A2,$C2-1), ENTER.
E2: =MID($A2,$C2+1,$B2-$C2-1), ENTER.
F2: =RIGHT($A2,LEN($A2)-$B2), ENTER.
Autofill B:F.
If temporary columns B:C are unwanted - you should replace references to them in D:F for B:C contents (i.e. replace $A2 in =LEFT($A2, with A2 actual formula), but this will result in TOO complicated ARRAY formulas, still doing their job - but difficult to understand the next day even for the creator)
As for the above solution - perhaps it might be improved or simplified, but I'm pretty much familiar with such ROW...INDIRECT constructions from times I had to analyze megabytes of statistic data, so for me it's just as easy as create LEFT / RIGHT. Anyway, it seems to work.
For your convenience my sample file is shared: https://www.dropbox.com/s/p49x32t3a0igtby/StringHyphensSeparate.xlsx
Hope that was helpful)
ADDITION - 2 more simplified solutions to find LAST TWO hyphens (the rest of steps is the same as above):
More simple ARRAY formulas:
B2 (MAX "-"): type the formula =MAX(IF(MID($A2,ROW(INDIRECT("1:"&LEN($A2))),1)="-",ROW(INDIRECT("1:"&LEN($A2))),0)) but press CTRL+SHIFT+ENTER instead of usual ENTER - this will define an ARRAY formula and will result in {} brackets around it (but do NOT type them manually!).
C2 (2nd MAX "-"): type the formula =LARGE(IF(MID($A2,ROW(INDIRECT("1:"&LEN($A2))),1)="-",ROW(INDIRECT("1:"&LEN($A2))),0),2) and again press CTRL+SHIFT+ENTER.
Regular formulas using SUBSTITUTE function:
B2 (MAX "-"): type the formula =SEARCH("#",SUBSTITUTE($A2,"-","#",LEN($A2)-LEN(SUBSTITUTE($A2,"-","")))), ENTER.
C2 (2nd MAX "-"): type the formula =SEARCH("#",SUBSTITUTE($A2,"-","#",LEN($A2)-LEN(SUBSTITUTE($A2,"-",""))-1)), ENTER.
The key for SUBSTITUTE solution is that it may replace only certain instances of matches, i.e. only 2nd or 3rd hyphen. The overall number of hyphens is determined again via SUBSTITUTE formula: length of original string MINUS length of string with ALL hyphens replaced to empty strings: LEN($A2)-LEN(SUBSTITUTE($A2,"-","").
One more trick here - while we should remain the original string intact, we still MAY do anything with it for intermediate solutions! Thus, we replace the hyphen with #, and then search for # in temporary string.
All the above solutions are working, choose what you like / understand better. Hope that will also help in understanding array formulas, since for the same task there are 2 different approaches.
I updated the example file to include the last 2 examples + resulting megaformulas without intermediate steps, link is the same and located above. Good luck!
Here is a less than perfect solution:
Do a search & replace to get rid of any dashes that are not delimiters. For example, replace "mozilla-nss" with "mozillanss"
Put your values in Column A starting at A1
In B1, enter =LEFT(A1,FIND("-",A1)-1)
In C1, enter =SUBSTITUTE(A1,B1,"")
In D1, enter =SUBSTITUTE(LEFT(C1,FIND("-",C1,2)),"-","")
In E1, enter =SUBSTITUTE(SUBSTITUTE(C1,D1,""),"-","")
Fill Down the equations for all your values in Column A.
Edit: Added next line:
Replace "mozillanss" with mozilla-nss".
Your answers are in columns B,D, and E.

Excel text formula to extract words separated by semicolons in a field

A field in Excel contains words separated by semicolons, e.g.:
A1 = save;the;national;treasure;for;good
How can I apply Excel text formulas to produce separate words from this field in another fields? E.g.:
A2 should contain a formula to get the first word ("save")
A3 should contain a (different) formula to get the second word ("the")
etc.
However these formulas should hold good even when the value in A1 changes, e.g. if the value of A1 is changed to
A1 = hello;there;how;are;you
Any help in this respect will be highly appreciated.
(The problem is writing a function of my own is not allowed in this case, I have to use original functions like find, search, mid, etc.)
You can create a VBA function to split the fields from this example:
Function ExtractElement(str, n, sepChar)
' Returns the nth element from a string,
' using a specified separator character
Dim x As Variant
x = Split(str, sepChar)
If n > 0 And n - 1 <= UBound(x) Then
ExtractElement = x(n - 1)
Else
ExtractElement = ""
End If
End Function
Then the A2 formula would be: =ExtractElement(A1, 1, ";") and A3 would be: =ExtractElement(A1, 2, ";") and so on
If you have your text to parse in A1 then the following formulas should work
In A2 enter the formula
=IF(ISERROR(LEFT(A1,FIND(";",A1)-1)),A1,LEFT(A1,FIND(";",A1)-1))
In B2 enter the formula
=IF(ISERROR(RIGHT(A1,LEN(A1)-FIND(";",A1))),"",RIGHT(A1,LEN(A1)-FIND(";",A1)))
You can then copy those down as far as you need. Column A grabs the left most word, and Column B displays the remaining string to be parsed. If it runs out of words to parse the formula will display a blank. Column B can also be hidden.
If you can use intermediate formulae, then this will work:
A1 -- save;the;national;treasure;for;good
B1 -- blank
C1 -- =IFERROR(FIND(";",$A1,1+(B1)),LEN($A1)+1)
copy C1 into D1:H1
C2 -- =MID($A1,B1+1,(C1-B1)-1)
copy C2 into D2:H2
Row 1 will display the position of each semi-colon in A1, because it starts looking in the string one character past the semi-colon found in the previous cell.
eg cell E1 searches for a semi-colon in A1 starting at D1+1 =10.
The iferror statement in C1:H1 traps the error which will occur when the search finds no further semi-colons, and returns the full length of string A1, plus 1 for an imaginary semi-colon at the end.
B1 needs to be blank to create an initial zero.
Cells C2:H2 then use the Mid function to copy the section of the A1 string starting one character after the value in each of B1:G1, with length (C1-B1)-1, (d1-c1)-1 etc (minus one to cut out the semi-colon itself)
You should get: 5, 9,18,27,31,36 in Row 1, and beneath those cells the individual words.
Hope this helps.

Resources