I'd like the output to be 10 and 200.
You should also try
=ArrayFormula(IFERROR(REGEXEXTRACT(B2:B, ".* (\d+) /.*")*1))
Or omit the arrayformula and drag down
=IFERROR(REGEXEXTRACT(B2, ".* (\d+) /.*")*1)
Other suggested solution may work for the given example.
Think ahead though for a more concrete solution in situations like
column B
--------------------------------------------------------------------------
Medical Face Shield - Pack - 10 / Next Day Shipping
KN95 Protective Mask - Type B - Carton - 200 / Next Day Shipping
MM - 33 Face Shield - 555 / - Type B - Carton - 1000 / Next Day Shipping
Functions used:
REGEXEXTRACT
ArrayFormula
IFERROR
#Catherine, your image doesn't show the range where your raw data resides nor where you want the results. And you've only allowed us to see two examples. But based on those two examples, and supposing that your raw data were in B2:B, delete everything from A2:A (or use another empty column) and place the following formula in A2 (or parallel):
=ArrayFormula(IF(B2:B="",, REGEXEXTRACT(B2:B, "- ([0-9]+)")))
This reads (in plain English): "If any cell from B2 down is blank, don't put anything in the results column. If it's not blank, extract from whatever is in the current row in Column B any group of numbers that follows a dash-and-space combination."
Everything in quotes within the REGEXEXTRACT denotes what to look for, while what is in parentheses denotes the part of that to extract.
If you need to count or do math with the extracted portions, add a VALUE wrap to the REGEXEXTRACT like this:
=ArrayFormula(IF(B2:B="",, VALUE(REGEXEXTRACT(B2:B, "- ([0-9]+)"))))
Related
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
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.
Many times, I am required to provide some type of break-down to the customers - an example is shown in the attached figure.
I have a table of data ("TABLE DATA" - which is some type of pivot) + Customer provides its official form, its structure must be preserved (highlighted in yellow ). Basically, I need to separate the cost details of CODE "A" and CODE "B" into 2 separated sections.
Customer requires me to provided details for each individual Part (example shows Part A - "Break-Down Part A)
Is there anyway to put a"ITEM" from "TABLE DATA" into Code A and Code B ? the rests can be solved by Vlookup (Price, Quantity) - note: "ITEM" is non-duplicated values . Thank you very much
Number your rows in the breakout using =1 and =A1+1 and then just use the formula ="B-ITEM"&TEXT(A1,"000"). If you want to skip making a counter column you could use ="B-ITEM"&TEXT(ROW()-1,"000") to just use the current row number (minus 1 or however many you need).
If your items aren't sequentially like that, but still unique, I would recommend adding counters on the original tab similar to what you have, which would let you quickly find the 5th A or 7th B, something that counts the previous instances of your current type, and then adds 1. For Row 6 you could do =COUNTIF(A$1:A5,A6)+1.
I have a data set that looks like this:
$40/5y 6m
$25/12y
$57/5y
$25/10y
$44/3y, $45.32/3y, $46.68/3y, $48.08/3y, $49.52/3y
$67/5y, $72/5y
$28/5y
I need to multiply the dollar amounts by their respective year and sum them if there is more than one. For example the first row would need to be 40*5.5 and the second to last row would need to be (67*5) + (72*5). I tried text to columns and a bunch of find and replace, but it was such a messy solution and didn't really work as planned. So, should I learn how to do macros or is this something that can be done with simple formulas?
See if this works:
1) Copy everything into Microsoft Word
2) Open "find and replace" and do the following replacements ("use wildcard characters" should be unchecked):
- replace (one space) with nothing
Then these have no spaces:
- replace $ with ^t
- replace / with ^t
- replace y, (with the comma) with ^t^t
- replace y with ^t
- replace m with nothing
Now paste this back in an Excel spreadsheet. You should have your data separated in cells like this:
(empty), dollars, years, months, (empty), dollars, years, months, (empty), dollars, years, months...
So then you could just make a partial calculation every 3 cells =dollars*(years+(months/12)) and then sum these partials into one total.
Would this help?
I made a custom phone format ###-###-#### so that a phone # can be entered only as 5555555555 => 555-555-5555 or as 555-555-55555.
I need a non-vba solution i.e one I can enter in the Data Validation window that checks the cell length and validates it if the length is 10 OR 12.
I have been trying for a long time but can not get it by trial and error or googling.
My best guess is (which does not work)
=IF((LEN(E2:E32)=12,0),( LEN(E2:E32)=10,0))
Thanks
This is not easy since Excel does not have a built in pattern matching function - you can only use built in functions in validation checks.
There is a solution though!
Fortunately you can check validation based on the state of a dependent cell. That's the approach we'll take here.
1) Your first job is to format the telephone number as text (my functions assume you've done this) so Excel doesn't trim leading zeros. In practice you'd format the whole column that way. Let's assume cell A1 will contain the phone number.
2) The validation formula will be ridiculously large if you attempt to put it in one cell and will be difficult to maintain. What we will do is put the validation stuff "off-spreadsheet"; i.e. in a column that's normally not visible to the user. That said, we'll use columns B,C and D for clarity. (Just cut and paste these elsewhere once you're done).
3) In B1 put =OR(C1,D1)
4) In C1 put =IFERROR(IF(LEN(A1)=10,VALUE(A1)*0 + 1,FALSE),FALSE). This validates the format with no dashes.
5) In D1 put =IFERROR(IF(OR(LEN(A1)=12,LEN(A1)=13),IF(AND(MID(A1,4,1)="-",MID(A1,8,1)="-"),VALUE(LEFT(A1,3) & MID(A1,5,3) & MID(A1,9,32767)) * 0 + 1,FALSE),FALSE),FALSE). This validates the format with the dashes.
Three tricks I'm using are (i) IFERROR is used to write False if the result would otherwise be #VALUE. This allows me to be more woolly in the programming, and (ii) the VALUE(n) * 0 + 1 pattern returns 1 if n is a number and, conveniently will compute #VALUE and delegate this to the surrounding function if n is not a number. Finally (iii) the 32767 in the MID function allows us to compare the remaining characters in a string without having to use a more clumsy RIGHT expression. 32767 is the limit on the number of characters in a cell. Perhaps I'm out by 1 here; no downvotes due to that please ;-)
6) Lastly, for cell A1, choose custom validation and set =B1 as the validation formula.
This does it! It will pass all your three formats:
5555555555, 555-555-5555 or 555-555-55555 where you've used 5 as a wildcard digit.