retrieve part of the info in a cell in EXCEL - excel

I vaguely remember that it is possible to parse the data in a cell and keep only part of the data after setting up certain conditions. But I can't remember what exact commands to use. Any help/suggestion?
For example, A1 contains the following info
0/1:47,45:92:99:1319,0,1320
Is there a way to pick up, say, 0/1 or 1319,0,1320 and remove the rest unchosen data?
I know I can do text-to-column and set the delimiter, followed by manually removing the "un-needed" data, but my EXCEL spreadsheet contains 100 columns X 500000 rows with each cell looking similar to the data above, so I am afraid EXCEL may crash before finishing the work. (have been trying with LEFT, LEN, RIGHT, MID, but none seems to work the way I had hoped)
Any suggestion will be greatly appreciated.

I think what you are looking for is combination of find and mid, but you'll have to work out exactly how you want to split your string:
A1 = 0/1:47,45:92:99:1319,0,1320 //your number
B1 = Find(“:“,A1) //location of first ":" symbol
C1 = LEN(A1) - B1 //character count to copy ( possibly requires +1 or -1 after B1.
=Left(A1,B1) //left of your symbol
=Mid(A1,B1+1,C1) //right size from your symbol (you can also replace C1 with better defined number to extract only 1 portion
//You can also nest the statements to save space, but usually at cost of processing quantity increase
This is the concept, you will probably need to do it in multiple cells to split a string as long as yours. For multiple splits you probably want to replicate this command to target the result of previous right/mid command.
That way, you will get cell result sequence like:
0/1:47,45:92:99:1319,0,1320; 47,45:92:99:1319,0,1320; 92:99:1319,0,1320; 99:1319,0,1320......
From each of those you can retrieve left side of the string up to ":" to get each portion of a string.
If you are working with a large table you probably want to look into VB scripting. To my knowledge there is no single excel command that can take 1 cell and split it into multiple ones.

Let me try to help you about this, I am not a professional so you may face some problems. First of all my solution contains 2 columns to be added to the source column as you can see below. However you can improve formulas with this principle.
Column B Formula:
=LEFT(A2,FIND(":",A2,1)-1)
Column C Formula:
=RIGHT(A2,LEN(A2)-FIND("|",SUBSTITUTE(A2,":","|",LEN(A2)-LEN(SUBSTITUTE(A2,":","")))))

Given you statement of having 100x columns I imagine in some instances you are needing to isolate characters in the middle of your string, thus Left and Right may not always work. However, where possible use them where you can.
Assuming your string is in cell F2: 0/1:47,45:92:99:1319,0,1320
=LEFT(F2,3)
This returns 0/1 which are the first 3 characters in the string counting from the left. Likewise, Right functions similarly:
=RIGHT(F2,4)
This returns 1320, returning the 4 characters starting from the right.
You can use a combination of Mid and Find to dynamically find characters or strings based off of defined characters. Here are a few examples of ways to dynamically isloate values in your string. Keep in mind the key to these examples is the nested Find formula, where the inner most Find is the first character to start at in the string.
1) Return 2 characters after the second : character
In cell F2 I need to isolate the "92":
=MID(F2,FIND(":",F2,FIND(":",F2)+1)+1,2)
The inner most Find locates the first : in the string (4 characters in). We add the +1 to move to the 5th character (moving beyond the first : so the second Find will not see it) and move to the next Find which starts looking for : again from that character. This second Find returns 10, as the second : is the 10th character in the string. The Mid formula takes over here. The formula is saying, Starting at the 10th character return the following 2 characters. Returning two characters is dictated by the 2 at the end of the formula (the last part of the Mid formula).
2) In this case I need to find the 2 characters after the 3rd : in the string. In this case "99":
=MID(F2,FIND(":",F2,FIND(":",F2,FIND(":",F2)+1)+1)+1,2)
You can see we have simply added one more nested Find to the formula in example 1.

Related

Extracting certain numbers from a cell containing numbers and special characters

I have cells that contain both numbers and special characters such as this:
[1:250:10]
The 'coordinates' shown above can be in the following format.
[(1-9):(1-499):(1-15)] in terms of what numbers can be within each part.
How do I extract these three numbers into three separate cells?
Assuming your data is in Cell A1 the to extract first number use following formula
=MID(A1,2,(FIND(":",A1,1)-2))
for second number use
=SUBSTITUTE(MID(SUBSTITUTE(":" & A1&REPT(" ",6),":",REPT(":",255)),2*255,255),":","")
finally for third number enter
=SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE(A1,":",REPT(" ",LEN(A1))),LEN(A1))),"]","")
Just tossing out some other options.
First number since it only has a length of 1 digit and is on the left side, use the following:
=RIGHT(LEFT(A1,2))
second number will be found by locating the : in the string
=MID(A1,FIND(":",A1)+1,FIND(":",A1,FIND(":",A1)+1)-(FIND(":",A1)+1))
third number will be dealt with in the same way as the second but we will use the second : and the ] as the identifiers as to where to grab from and how much to pull.
=MID(A1,FIND(":",A1,FIND(":",A1)+1)+1,FIND("]",A1)-(FIND(":",A1,FIND(":",A1)+1)+1))
now all those number will actually come through as text. If you want to have them as numbers in the cells, send them through a math operation that will not change their value. Do something like +0, -0, or *1 at the end. Alternatively you could add -- at the start of each formula (yes that is double - incase you were wondering if it was a typo)

Count the number of individual entries in a cell

Is it possible to count the number of individual entries in a cell?
For example 2+2+4-1 = 4 entries
Using the count formula counts the entries as 1
I want to calculate the number of adjustments made in a particular period.
Each +/- in an individual cell represents 1 adjustment.
Assuming you're referring to a text cell, the trick is to count the symobols you'd like to find. Before we dig into that, if you want to enter this data as text, you can use the ` symbol (Usually to the left of the 1 key on your keyboard) before entering your text to make sure it gets processed as text.
If you want to verify that it is text, you can use the TYPE function and look for a return result of 2 (check the link for other possible return types)
There are no direct functions to count characters in Excel, so the trick is to find the length of the original text and subtract it from the length of a new text where you have removed all of the special characters. You mentioned you were trying to count the entries (i.e. the numbers), but you said your goal was to ultimately count the number of '+/-' operations. Since counting numbers can be tricky with excel formulas (since we'll get hung up on 2 and 3 digit numbers), I am going to approach this problem from the perspective of counting the operations you are looking for. So here is a basic example:
length("2+1") = 3
- length("21") = 2 (we replaced the + with "" [blank])
= 1
So we know there is 1 '+' since we replaced it. The appropriate functions used to accomplish this are LEN and SUBSTITUTE
Since you can only find one symbol at a time using the SUBSTITUTE function, we must take the output of the first formula, and give it to the second formula, and so on and so forth. Ultimately, we can put together as many functions as we need to achieve the desired result.
So we start with + for your example (And assuming your data is in A1)
=LEN(A1)-LEN(SUBSTITUTE(A1,"+",""))
which gives us a result of 2. But we also need to find the - symbol. So we wrap another SUBSTITUTE:
=LEN(A1)-LEN(SUBSTITUTE(SUBSTITUTE(A1,"+",""),"-",""))
You have said you wanted to count the number of +/- in the cell, and this does accomplish that, but if you want to expand it to more mathematical operators, you simply add more SUBSTITUTE functions (here is a complete function where I've added * and /)
=LEN(A1)-LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"+",""), "-",""),"*",""),"/",""))
Well, this formula would replace all your numbers with "" and then Count the +/- and adds one, should do it, but is ugly:
=LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1;"0";"");"1";"");"2";"");"3";"");"4";"");"5";"");"6";"");"7";"");"8";"");"9";""))+1
Could probably be done with RegEx, but I don't know how to do that in formulas
This makes 31+12+3-4 to ++-, Counts the LEN (3) and adds 1

How to modify numbers at the end of a cell using a formula

I have cells in excel containing data of the form v-1-2-1, v-1-2-10, v-1-2-100. I want to convert it to v-1-2-001, v-1-2-010,v-1-2-100. I have nearly 2000 entries
If all of the data follows the format shown then you could use FIND to return the position of '-'. There will be three instances of this character and you need to find the third one so use the position given by the first instance as the start position parameter of the second FIND and again for the third (essentially nesting FIND). Once you have the position of the third '-' you know where the final set of numbers are (from the returned third position+1 to the LEN of the string) and could use SUBSTITUTE or a combination of other excel string functions to configure the final portion as you need it.
I'm assuming that excel has your data formatted as text.
If you need further assistance I'm happy to knock up the formula in excel but I'm off to work now and won't be able to do so for around 9 hours.
Please try:
=LEFT(A1,6)&TEXT(MID(A1,7,10),"000")

finding dynamically a match between two tables; one has text and the other the search pattern

EXCEL - finding a match between two tables
https://drive.google.com/folderview?id=0B2WLaA0HlUBVWnlwaFRGMmdwaVU&usp=sharing - excel file
FILE : vraag.xlsm
I would like to make a dynamically solution, for searching a text pattern from one table if it is also in the text of an other table (in different columns).
(Dynamically, I mean if the are elements are added, deleted, changed)
So searching if one the elements from column 'ID_type' can be found in the text of column 'element'
!
table A [T_example] : in a column contains tekst (within maybe one
of the elements of the other table)
table B [T_rec_by_type] : contains several possible strings
edited : next seems to be a wrong approach : MATCH()
=IF(ISNA(VLOOKUP(A23;T_rec_by_type[ID_type];1;FALSE));FALSE; "File found in row " & MATCH(A23;T_rec_by_type[ID_type];0))
In the first example (exactly match, so not as search pattern), it works.
But the idea is to search in the text to find the searchpattern ... and return via VLOOKUP a value from an other column (in this stadium just ID_type).
A possible solution found in an answer online
EXCEL - Find category by searching keyword from other worksheet
https://drive.google.com/folderview?id=0B2WLaA0HlUBVWnlwaFRGMmdwaVU&usp=sharing - excel file
FILE : SearchAMatchtingStad.xlsm
In the hope to find a solution ... for my case via this answer, I tried it out but unfortunately without succes.
So what am I doing wrong?
(I tried it first with tables, columns and ...
=IFERROR(IF(INDIRECT("Sheet1!A"&MAX(IF(ISERROR(SEARCH(CONCATENATE("*";Table1[[stad 1]:[stad 3]];"*");[#shop]))+(Table1[[stad 1]:[stad 3]]="");0;ROW(Table1[[stad 1]:[stad 3]]))))=Table2[[#Headers];[antwerpen]];[#sales];"");"Not found")
to figure out my fault/problem, why it doesn't work ...
I did it just by one cell, but without luck)
= IFERROR( IF( INDIRECT("Sheet1!A" & MAX( IF( ISERROR( SEARCH("*"&Sheet1!$B$2:$D$4&"*";$B8)) + (Sheet1!$B$2:$D$4="") ; 0 ; ROW(Sheet1!$B$2:$D$4)))) = D$7;$C8; "") ; "Not found")
A small remark ENTERING AN ARRAY FORMULA: press the CTRL SHIFT and ENTER
In a way it seems that there is an issue with array formulas
So when I do a one to one 'search' it seems to work =SEARCH("*"&B2&"*";$B8)
But when I do it with an array (despite it is still an array but with "\" instead of { "genk" ; "mol" ; "leuven" ; ... }), it seems to be a problem, or not working the way I wished. =SEARCH(CONCATENATE("*";OR(Table1[[stad 1]:[stad 3]]);"*");B8)
So I give it a last try.
But with OR or without gives the same result.
And to check if it maybe a problem is with CONCATENATE, I created a simular table with the wildcard already implemented.
Maybe ONE important thing, I forget to say there is always a space in front of the ID_TYPE.
And the ID_TYPE itself followed by a number (of maximum 3 characters) and a space.
You may have to change ; to , and , to . according to your local.
#Tom Sharpe
Thanks for your answer, but when I tried it out, it doesn't work.
Maybe ONE important thing, I forget to say there is always a space in front of the ID_TYPE.
And the ID_TYPE itself followed by a number (of maximum 3 characters) and a space.
I used 0 - in case default, not found.
Correct Tom, if I use '=FORMULATEXT(B35)', I see the formula is surrouded by { and }.
So I don't understand what I'm doing wrong.
And it worked fine at your place, you did it with my spreadsheet? Strange.
I uploaded the file changed as "vraag2.xlsm"
#user3616725
Maybe ONE important thing, I forget to say there is always a space in front of the ID_TYPE.
And the ID_TYPE itself followed by a number (of maximum 3 characters) and a space.
put new file in the shared folder : vraag2.xlsm
Here's another solution without using Regex. It tests each element in the first column of the table in A1:A7 (ID_type) using FIND to see if it is a substring of the element in A25 and below. The row numbers of any matching cells in a1:a7 are stored in an array. Because you want the first match, it uses MIN to find the lowest row number. If there is no match, it stores a reference to a cell which is outside the table, i.e. A8. I'm using FIND because I don't want to match lowercase, otherwise ... "3 spots plafond" would match with A because it has an 'a' in it.
If you enter the array formula in (say) d25 and pull it down, it will give the row number of the first matching cell in the table. If you enter the second formula in (say) e25 and pull it down, it will give the corresponding cell in another column of the table, in this case column B (type).
The first formula in structured form is:-
=MIN(IF(ISERROR(FIND(T_rec_by_type[[#Data],[ID_type]],A25)),ROW(A$8),ROW(T_rec_by_type[[#Data],[ID_type]])))
and the second one in structured form is
=IFERROR(INDEX(T_rec_by_type[[#All],[type]],D25),"Not found")
The formulae in ordinary notation (which I find a bit easier) are
=MIN(IF(ISERROR(FIND(A$2:A$7,A25)),ROW(A$8),ROW(A$2:A$7)))
and
=IFERROR(INDEX(B$1:B$7,D25),"Not found")
ROW(A$8) above is just a not very subtle way of getting a row number which is greater than that of any rows in the table. You could just use an arbitrary large number, or perhaps add a Totals row to the first table and use that to get the reference.
I haven't been able to work out why your vlookup didn't work with the table (it's OK if I copy the cells somewhere else), perhaps other people can comment.
using REGEX functions from MORFUNC ADDON*
I used your vraag.xlsm shhet that you linked to.
In cell C25 put: =REGEX.MID(TABLE12[[#ThisRow],[element]],MCONCAT(T_rec_by_type[ID_type],"|"),,TRUE)
this will give you the first (left-most) of the "keywords" that appears in the corresponding "element" cell.
This is almost there. but you say that the "SSR" sensor is more important than V, so that's the one that should be displayed if they both appear.
this is not pretty, but will work (if u provide more details on possible "ID_type"s and the order of things in "element" field i might be able to come up with something more elegant...) :
paste in cell D25:
=IF(REGEX.COMP(Table12[[#This Row],[element]],A$2,TRUE),A$2,IF(REGEX.COMP(Table12[[#This Row],[element]],A$3,TRUE),A$3,IF(REGEX.COMP(Table12[[#This Row],[element]],A$4,TRUE),A$4,IF(REGEX.COMP(Table12[[#This Row],[element]],A$5,TRUE),A$5,IF(REGEX.COMP(Table12[[#This Row],[element]],A$6,TRUE),A$6,IF(REGEX.COMP(Table12[[#This Row],[element]],A$7,TRUE),A$7,""))))))
copy C25 and D25 down, for the other elements
MOREFUNC ADDON
Morefunc Addon is a free library of 66 new worksheet functions.
HERE is some information (by original author)
here is the last working download link I found
here is a good installation walk-through video

I'm trying to make a formula that checks a number in excel, but the cell has to include the dashes

I have something like this:
A1: ABC-DE442
B1: 0069-1234-12
I'm trying to make a formula that will look at A1, get the number 442, and then check if B1 is in the format of 4 numbers, a dash, 4 numbers, a dash, and then finally 2 numbers. I want to make sure that this could work with any number besides 442 though. So if I had like 123 instead of 442, it would need to be 1 number, dash, 2 numbers, dash, and three numbers.
It would also need to give me an error if I had something like this:
A1: ABC-DE442
B1: 004-2345-34
because it only has three numbers in the first section before the dash.
Hopefully I have been clear enough in what I'm trying to do. Any help would be greatly appreciated.
So in the end, this is the giant formula I had to create:
=IF(LEN(LEFT(J4,FIND("-",J4)-1))=VALUE(MID(I4,9,1)),IF(LEN(LEFT(MID(J4,FIND("-",J4)+1,999),FIND("-",MID(J4,FIND("-",J4)+1,999))-1))=VALUE(MID(I4,10,1)),IF(LEN(MID(MID(J4,FIND("-",J4)+1,999),FIND("-",MID(J4,FIND("-",J4)+1,999))+1,999))=VALUE(MID(I4,11,1)),"True","Doesn't match code part 3"),"Doesn't match code part 2"),"Doesn't match code part 1")
J15: 0069=LEFT(J5,FIND("-",J5)-1)
J16: 4=VALUE(MID(I5,7,1))
J17: 4=LEN(J15)
J18: 0469-56=MID(J5,FIND("-",J5)+1,999)
J19: 0469=LEFT(J18,FIND("-",J18)-1)
J20: 4=VALUE(MID(I5,8,1))
J21: 4=LEN(J19)
J22: 56=MID(J18,FIND("-",J18)+1,999)
J23: 2=VALUE(MID(I5,9,1))
J24: 2=LEN(J22)
Hopefully all of these formulas will make it easier to understand how I combined everything together.
I essentially put every formula into one giant one using the information used in the answer I said was right. For the first part, I took the LEN(D1) but had it all written out, and then set it equal to the =VALUE(MID(A1,7,1)).
Then, for the true part of that if statement, I had to first get A1 without D1, then get it to just be the middle section using the LEFT formula, and then finally taking the LEN of that. Checked to see if it was equal to the =VALUE(MID(I4,10,1)), which was the next number in B1.
If that was true, I went to the final IF statement which again had to go through the same process of getting the last section of A1 on it's own, taking the length of that, and seeing if it was equal to =VALUE(MID(I4,11,1)).
Finally, I just created different print statements for the last true, and every false section of the IF statements.
Moral of the story, I was able to make a formula that works with every single number combination because it turns out B1 could only be in the form of AB - CDE###, so I could always find that number in B1 and compare it.
This should be possible with Excel formulae but it will get a bit complicated. The functions you're probably going to want to make use of are FIND, LEFT, LEN, MID, and VALUE.
For example,
C1: =FIND("-",B1)
will return the position of the first dash in the string to be tested, which for your example is 5. Then
D1: =LEFT(B1,C1-1)
would return the characters before that dash, i.e. '0069'. Meanwhile you need to get the lengths of the three runs of digits out of your first string (the one in A1). Will that string always be the same length? If so you can use e.g.
=VALUE(MID(A1,7,1))
which returns the 7th character of the string in A1 and converts it to a number (4). Now you can test whether that value is equal to the length of the first run of characters, i.e. LEN(D1).
But are those characters all numeric? Well, you can try converting them to a number with VALUE(D1) which will return #VALUE if the argument can't be made into a number.
OK, that checked the first run of characters, what about the rest of them? Well,
=MID(B1,FIND("-",B1)+1,999)
will give you the remainder of the original string after the first dash, which you can analyse in the same way, and so on.
It's easiest to develop these formulae by using lots of cells to hold the intermediate values as you work them out, but once you're confident these are working OK you can consolidate them into fewer cells. Whatever you come up with, make sure you test it with lots of different inputs to check that your formulae respond to them in the way that you expect. (In particular, check what happens if you have one or more spaces after a dash, as VALUE will ignore leading spaces - you might want to use a SUBSTITUTE function on your initial text to remove any spaces.)

Resources