I want to extract 2 from the string in cell C3 and return it as the result of the function in cell E3:
Probably SPLIT is the wrong approach here.
Edit:
I replaced the 2 with s because some approaches work for numbers but not for letters:
Try the following
=REGEXEXTRACT(A1,"\d")*1
Following OP's edit
=REGEXEXTRACT(A2,";(.*),")
Please read more about REGEXEXTRACT
Related
I am trying to use the result of a concatenation of a string and cell contents in a query, but the query function does not seem to like it: see this example
https://docs.google.com/spreadsheets/d/1CtPFLhpD3KDHrk-6WoHft4JdMTVa3OcvHHqAidMWwdM/edit?usp=sharing
The strings in cells B2 and B3 appear to be the same, but whilst C3 gives the desired result, C2 does not. B3 simply extracts a string from A3, whereas B2 tags the 'E' on in the formula. The data in the real spreadsheet I am working with is like that in B2, so I have to add the 'E' into the result. The real list of error codes is quite long and varied, so I cannot edit that to just use the number. I also tried using CONCATENATE, but that made no difference.
How do I get the query to recognise the contents of C2 as the string 'E151'?
Most likely there's an trailing space in the result of B2.
See if this helps
=query(A7:B10,"select B where A = '"&trim(B2)&"'",0)
In B2
="E"&mid(A2,30,3)
or
="E"&index(REGEXEXTRACT(A2,REGEXREPLACE(A2,"(\d+)","($1)")),1,5)
(the 5th number in the string)
delete everything in column C and use this in C2:
=INDEX(IFNA(VLOOKUP(TRIM(B2:B4), A7:B11, 2, 0)))
Some great answers to my question, thanks! It was a trailing space causing the problem.
I have combined some of the ideas in the other answers in the real spreadsheet and used
="E" & trim(mid(A2,30,3))
Since some of the error codes are only 2 characters long
Which formula can I use to remove the currency sign?
Anything smarter than: REPLACE(value,0,1)?
Your question is way too vague.
Having said that, let's cover different conditions
Cell as TEXT =C1*1
Cell as NUMBER =N(C2)
Raw Value =("$-123.55")*1
Try the following
=SUBSTITUTE(value, "$", "")
After many hours I finally figured out how to import data from <span>...
Yet right now I've hit next wall and I can't figure out what can help me in this situation.
After using:
=IMPORTXML("https://www.bodypak.pl/pl/aminokwasy/5890-6pak-nutrition-bcaa-pak-400g.html";"//span[#id='our_price_display']")
As result, we have 79,00 PLN, yet that is String and I can't figure out how to convert it to INT
For making everything easier cell where I'm importing data I will mark as #XML =Value('#XML')
don't work, same implemented formatting.
I also tried to export the result to another cell and format another cell but that didn't work either.
=LEFT(#XML,LEN(#XML)-3) leave me with 79,00 but still I can't convert it to Int.
And I'm quite stuck right now.
You can use the function split like this: split(str, separator, 0) and take the first item of the resulting array with
=index(split(arr,","),0,1)
All together:
=index(split(split(IMPORTXML("https://www.bodypak.pl/pl/aminokwasy/5890-6pak-nutrition-bcaa-pak-400g.html","//span[#id='our_price_display']")," "),","),0,1)
The formula above truncates the string at the ",". If you want to actually convert to integer, use int() after replacing the comma with a ".":
=int(value(substitute(split(IMPORTXML("https://www.bodypak.pl/pl/aminokwasy/5890-6pak-nutrition-bcaa-pak-400g.html","//span[#id='our_price_display']")," "),",",".")))
The cell contains text that matches the following pattern: number, unit, item, description. How can I extract the number from the cell to the consecutive cell
To extract the start of the string up until the first comma:
=REGEXEXTRACT(A1,"^(.+?),")
Definitely not as neat as #AdamL's solution but alternatives:
=ARRAY_CONSTRAIN(split(A1,","),1,1)
=value(left(A1,find(",",A1)-1))
I have a column XXX like this :
XXX
A
Aruin
Avolyn
B
Batracia
Buna
...
I would like to count a cell only if the string in the cell has a length > 1.
How to do that?
I'm trying :
COUNTIF(XXX1:XXX30, LEN(...) > 1)
But what should I write instead of ... ?
Thank you in advance.
For ranges that contain strings, I have used a formula like below, which counts any value that starts with one character (the ?) followed by 0 or more characters (the *). I haven't tested on ranges that contain numbers.
=COUNTIF(range,"=?*")
To do this in one cell, without needing to create a separate column or use arrayformula{}, you can use sumproduct.
=SUMPRODUCT(LEN(XXX1:XXX30)>1)
If you have an array of True/False values then you can use -- to force them to be converted to numeric values like this:
=SUMPRODUCT(--(LEN(XXX1:XXX30)>1))
Credit to #greg who posted this in the comments - I think it is arguably the best answer and should be displayed as such. Sumproduct is a powerful function that can often to be used to get around shortcomings in countif type formulae.
Create another list using an =ARRAYFORMULA(len(XXX1:XXX30)>1) and then do a COUNTIF based on that new list: =countif(XXY1:XXY30,true()).
A simple formula that works for my needs is =ROWS(FILTER(range,LEN(range)>X))
The Google Sheets criteria syntax seems inconsistent, because the expression that works fine with FILTER() gives an erroneous zero result with COUNTIF().
Here's a demo worksheet
Another approach is to use the QUERY function.
This way you can write a simple SQL like statement to achieve this.
For example:
=QUERY(XXX1:XXX30,"SELECT COUNT(X) WHERE X MATCHES '.{1,}'")
To explain the MATCHES criteria:
It is a regex that matches every cell that contains 1 or more characters.
The . operator matches any character.
The {1,} qualifies that you only want to match cells that have at 1 or more characters in them.
Here is a link to another SO question that describes this method.