How to extract numbers with separation in Excel - excel

Does anyone knows any formula to extract the number with separation (dot, comma) from cell A1 to cell B1?
Example, I want to extract 2,590.00 from cell A1 which has the following value:
[sum: 2,590.00]
I got the formula below that works nice, however is just getting all numbers e.g. 259000
{=TEXTJOIN("",TRUE,IFERROR((MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)*1),""))}
I appreciate every support

Under O365 you can try the following in cell B1 which is a very concise approach:
=TEXTAFTER(TEXTBEFORE(A1,"]"), "sum: ")
Here is the output:
For excel-2019, similar idea but using SUBSTITUTE instead to remove the prefix ([sum: ) and the suffix (]):
=SUBSTITUTE(SUBSTITUTE(A1,"[sum: ",""),"]","")

You can use a formula like as below:
• Formula used in cell B1
=MAX(IFERROR(--MID(SUBSTITUTE(A1,"]",""),ROW($ZZ1:INDEX($ZZ:$ZZ,LEN(A1))),LEN(A1)),0))
• With OFFICE 365, you can try this in cell C1
=--INDEX(TEXTSPLIT(A1,{":","[","]"},,1),,2)
• Formula used in cell D1
=SUBSTITUTE(TEXTAFTER(A1," "),"]","")*1

Related

How to do an if statement

This question is linked to Formula to remove every middle name in a cell in Excel.
I basically want to make an if else statement in excel. So the IFchecks if the cell is equal to "Gian" OR"Pier", if the condition is confirmed the formula proceeds to use this other formula
=IFERROR(LEFT(A2,FIND(" ",A2)-1),A2)
Sorry guys idk how to do it in an excel way. I can show you in for example in a Java or C way.
if(A2=="Pier" || A2=="Gian")
=IFERROR(LEFT(A2,FIND(" ",A2)-1),A2) \\the excel formula that deletes every second/third name if the cell
if formula in excel that checks a condition and if its verified it proceeds to use another excel formula
You could try the following as per your Excel Versions
• Formula used in cell B2
=IF(OR(TEXTBEFORE(A2&" "," ")={"Pier","Gian"}),A2,TEXTBEFORE(A2&" "," "))
Or, in cell C2
=IF(OR(LEFT(A2&" ",FIND(" ",A2&" ")-1)={"Pier","Gian"}),A2,LEFT(A2&" ",FIND(" ",A2&" ")-1))
Just adding the use of LET() which makes it simpler,
• Formula used in cell B2
=LET(x,TEXTBEFORE(A2&" "," "),IF(OR(x={"Pier","Gian"}),A2,x))
Or, Formula used in cell C2
=LET(x,LEFT(A2&" ",FIND(" ",A2&" ")-1),IF(OR(x={"Pier","Gian"}),A2,x))
Using MAP() to Spill as one dynamic array formula but the logic remains same.
• Formula used in cell D2
=MAP(A2:A6,LAMBDA(m,
LET(x,TEXTBEFORE(m&" "," "),
IF(OR(x={"Pier","Gian"}),m,x))))
you have to use the AND(...) and OR(..) for chaining logical conditions.
Here's an example

Why some of the content cannot be extracted

I need to extract this from the cell
For example:
A1 : abode abcd=1000seconds long=50cm
I need only 1000. With this sequence and this formula I can extract 1000 from the cell.
The formula I use is MID(A1, SEARCH(“=“,A1) + LEN(“=“), SEARCH(“seconds”,A1)-SEARCH(“=“,A1)-LEN(“=“))+0
However when the sequence of cell become:
A1 : long=50cmabode abcd=1000seconds
The 1000 cannot be extracted.
Please help
Edit, since OP mentioned they are using Excel 2016, formula changed accordingly
• Formula used in cell D2
=SUBSTITUTE(FILTERXML("<m><b>"&SUBSTITUTE(SUBSTITUTE(B2,"="," ")," ","</b><b>")&"</b></m>","//b[contains(., 'seconds')]"),"seconds","")
Alternative Approach,
• Formula used in cell C2
=SUM(IFERROR(--TEXTAFTER(TEXTBEFORE(B2,"seconds"),"=",{1,2}),0))

Use > or < sign dynamically in an excel formula

I am trying to create a formula which picks ">" or "<" sign depending upon whether any record has "Higher" or "Lower" against it.
For example, if A1 has "Higher", then formula in B1 should be =0.78>0.59
If A2 has "Lower", then formula in B2 should be =0.78<0.59
Try,
if(a1="higher", 0.78>0.59, 0.78<0.59)
'alternate
=or(and(a1="higher", 0.78>0.59), and(a1="lower", 0.78<0.59))
use this as formula.
=IF(A1>B1,">","<") in cell C.
than use this formula to get your desired look in next cell. =CONCATENATE(A2,C2,B2)
You can hide Column C if you don't want to show it.
Check it by clicking following link,

Extract a value from a cell if it matches a list of characters

I'm trying to extract a word from a sentence if it starts with one of the following letters.Dell** or Samsung** or Apple**. The position of the words may vary in the cell.
A1: Dell2622 Retail34792 Lenovo StoreQuantity4
A2: Retail9858 Qty8 Samsung783546 Android
A3: Retail21512 Apple3411 StoreQty15 Macintosh
I am trying to use the following formula to extract the Dell** or Samsung** or Apple** if it's present int the cell.
=MID(A1, SEARCH({"Dell","Samsung","Apple"},A1), SEARCH(" ",A1, SEARCH({"Dell","Samsung","Apple"},A1))- SEARCH({"Dell","Samsung","Apple"},A1))
It works for the cell A1, but everything else returns #VALUE!. I guess it doesn't recognize that i want it to check for either or and extract either or. The result I'm trying to achieve is:
A1: Dell2622
A2: Samsung783546
A3: Apple3411
Later on i may need to add more things to search for, so I'm trying to keep it easily modifiable. I guess since it finds the first instance, then it's just a matter of tweaking something to ensure that if it didn't find the first value it looks for second, etc.
Assuming you have a data setup similar to the picture below, with your strings in column A, the formula in column B, and the words to look for in column D:
The formula in cell B2 and copied down is:
=TRIM(LEFT(SUBSTITUTE(MID(A2,MIN(INDEX(SEARCH($D$2:$D$4,A2&$D$2:$D$4),)),255)," ",REPT(" ",255)),255))
And per your request to not use a range reference and instead have the list of words directly in the formula:
=TRIM(LEFT(SUBSTITUTE(MID(A3,MIN(INDEX(SEARCH({"Dell","Samsung","Apple"},A3&{"Dell","Samsung","Apple"}),)),255)," ",REPT(" ",255)),255))

Getting the Nth instance of an element

I have a column filled with data that has a path. I'd like to get the last element in the path, the second last element, and the first element. For example, for the following data:
\Product\Release\Iteration
\Product\Folder1\Folder2\Anotherfolder\Release2\Iteration5
\Product
\Product\Somefolder\Release3\Iteration5
I'd like to get the following in cells
In cell B1: "Product", cell C1: "Release", cell D1: "Iteration"
In cell B2: "Product", cell C2: "Release2", cell D2: "Iteration5"
In cell B3: "Product", cell C3: blank, cell D3: blank
In cell B4: "Product", cell C4: "Release3", cell D4: "Iteration5"
Getting the first and the last component is easy. I'm mostly just struggling with getting the second to last component (column C in the example above).
In B1 and copied down:
=TRIM(MID(SUBSTITUTE(A1,"\",REPT(" ",99)),99,99))
In C1 and copied down:
=IF(LEN(A1)-LEN(SUBSTITUTE(A1,"\",""))=2,TRIM(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",99)),99)),IF(LEN(A1)-LEN(SUBSTITUTE(A1,"\",""))>2,TRIM(LEFT(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",99)),198),99)),""))
In D1 and copied down:
=IF(OR(LEN(A1)-LEN(SUBSTITUTE(A1,"\",""))={1,2}),"",TRIM(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",99)),99)))
Assuming your data is in ColumnA use Text to Columns with \ as delimiter to split across columns B:G. Assuming a maximum of 8 elements, put =B1 in K1 and in L1:
=IF(AND(ISBLANK(D1),ISBLANK(C1)),"",IF(ISBLANK($D1),$C1,IF(ISBLANK(C1),"",INDIRECT("R"&ROW()&"C"&COLUMN()-COUNTBLANK($B1:$I1)-4,0))))
Copy L1 to M1 and K1:M1 down to suit.
Copy Paste Special Values over the top and delete columns A:I.
Made up two formulas to retrieve any part of the path you want:
Taking the first as starting from the left:
=IFERROR(MID(A3,FIND(CHAR(1),SUBSTITUTE(A3,"\",CHAR(1),C$2))+1,IFERROR(FIND("\",A3,FIND(CHAR(1),SUBSTITUTE(A3,"\",CHAR(1),C$2))+1)-FIND(CHAR(1),SUBSTITUTE(A3,"\",CHAR(1),C$2))-1,LEN(A3))),"")
Taking the first as starting from the right:
=IFERROR(MID(A3,FIND(CHAR(1),SUBSTITUTE(A3,"\",CHAR(1),LEN(A3)-LEN(SUBSTITUTE(A3,"\",""))+1-D$2))+1,IFERROR(FIND("\",A3,FIND(CHAR(1),SUBSTITUTE(A3,"\",CHAR(1),LEN(A3)-LEN(SUBSTITUTE(A3,"\",""))+1-D$2))+1)-FIND(CHAR(1),SUBSTITUTE(A3,"\",CHAR(1),LEN(A3)-LEN(SUBSTITUTE(A3,"\",""))+1-D$2))-1,LEN(A3))),"")
And here's a google spreadsheet where you can see how it's working.
Note: I had to make a few changes to the formulae to make it google-spreadsheet-compatible, namely:
Change CHAR(1) to something else, I used "/" as substitute
Add an IF() to check for SUBSTITUTE(,,,0) (the 0 parameter) since this gives an error in MS Excel but not on google spreadsheet.
If you just need to parse the data to cells, you could import a text file into Excel with '\' delimitor. Otherwise, you need to loop through with CHARINDEX() and SUBSTRING to find the position of each backslash and parse out the data in between.
You could also use SSIS and set up a text file transformation with '\' delimitor to Excel for automation. With TSQL, you need to loop as I suggested
This has an excellent example that uses the split command. You just need to change the | character to \ and use the loop to put the individual values in the places you want.
Break string based on a character in VBA 2010
This should work for you (assuming you don't use * in your file names which I don't think is allowed in windows anyways):
=RIGHT(A2,LEN(A2)-FIND("*",SUBSTITUTE(A2,"\","*",(LEN(A2)-LEN(SUBSTITUTE(A2,"\","")))-1),1))
That is for the second last element.
You can get any element you want by changing the bold number:
=RIGHT(A2,LEN(A2)-FIND("",SUBSTITUTE(A2,"\","",(LEN(A2)-LEN(SUBSTITUTE(A2,"\","")))-3),1))
EDIT/ADDITION
If you want to get rid of the values to the right of the nth element in the formulas above, you can do it like this:
=IFERROR(LEFT(RIGHT(A2,LEN(A2)-FIND("*",SUBSTITUTE(A2,"\","*",(LEN(A2)-LEN(SUBSTITUTE(A2,"\","")))-1),1)),FIND("\",RIGHT(A2,LEN(A2)-FIND("*",SUBSTITUTE(A2,"\","*",(LEN(A2)-LEN(SUBSTITUTE(A2,"\","")))-1),1)),1)-1),"error checking, lol")

Resources