Google Sheets - Cell contains text - if-statement

I have a google sheet with cells that contain different words. I want the words to equal numbers if present in a different cell. Normally I can just use =if when there is just one word but can't for this. I've tried using =regexactmatch and =search but can't get it to work.
For example the cell might contain the following text:
"Uruguay, France, Brazil, Belgium"
I want Uruguay, France, Brazil to each = 3 in another cell but Belgium to = 0 in that same cell.

I think does what you ask:
=substitute(substitute(substitute(substitute(A1,"Uruguay",3),"France",3),"Brazil",3),"Belgium",0)
but, possibly like user who VTC'd as Unclear, I doubt it is what you want.

Related

Highlight duplicates when part of the cell matches in Google Sheets

I have searched as much as I can, and I have found solutions for similar problems, but I haven't been able to find a solution to my exact problem.
Issue: I would like to highlight the row when one cell in column A of that row is an exact match for another cell in that column, AND part of another cell in column B of that row is a match for part of another cell in that column, in Google Sheets. I would like to use conditional formatting, and only highlight the second occurence and on.
For example, is this "sheet":
A B C
1|John Smith|john#test.com|Test Co.
2|Jane Doe |jane#x.com |X Company
3|John Smith|j.s#test.com |Test Inc.
4|John Smith|jsm#test.com |Test Incorporated
I would like row 3 and row 4 to highlight, because column A3 is a duplicate of A1, and everything in B3 after # matches everything in B1 after #, and the same is true of row 4. Also, only rows 3 and 4 should highlight; not row 1, since it is the first instance. I understand regexes, and I've found how to highlight a row if one cell in column A and one cell in column B is an exact match with other cells is their respective columns, but I haven't figured out how to combine the two where I can search for one cell that is an exact match with another cell in that column AND for one cell that is a partial match with another cell in that particular column. Here is a link to a test sheet that contains the sample info from above. https://docs.google.com/spreadsheets/d/1neZd213C1ssY7bPeBfu2xI3WPCmt-oKkfbdrXrid9I8/edit?usp=sharing
use:
=INDEX(COUNTIFS($A:$A&REGEXEXTRACT($B:$B, "#.+"), $A1&REGEXEXTRACT($B1, "#.+"),
ROW($A:$A), "<="&ROW($A1))>1)*(A:A<>"")
Try the following custom formula applied to A1:C:
=index((countif($A$1:$A1,$A1)>1)*
(countif(regexextract($B$1:$B1,"#(.*)"),
regexextract($B1,"#(.*)"))>1))

How to extract a set of numbers from a cell and add them up in Google sheets

I have an input cell which contains a list of expenses/prices in a string form and would like to extract all numbers and add them up in an output cell.
From the list of items below for example, I would like to see on the adjacent right cell the total of ยฃ290.89.
How do I achieve this on Google sheets?
You can also try
=SUM(SPLIT(REGEXREPLACE(K1,"(.*ยฃ|.*- )","#"),"#"))
i think this might work if that is an image of cell B2.
=SUM(INDEX(SPLIT(TRANSPOSE(SPLIT(B2,CHAR(10))),"- ",0),,2)
Another one, which assumes that prices have a pound sign or a decimal place:
=sum(split(regexreplace(regexreplace(A1,"\s\d+\s"," "),"[^\d\.]"," ")," "))

Regexmatch in Google Sheet to identify cells that include any string in another sheet

I have a ColumnA where each cell include multiple values separated by comma, eg:
Elvis Costello, Madonna
Bob, Elvis Presley, Morgan Stanley
Frank, Morgan Stanley, Madonna Ford,
Elvis Costello, Madonna Ford
And I want to identify which rows/cells that includes any of the exact terms in another sheet/column, eg
Elvis Presley
Madonna
And I found this simple solution using Regexmatch (the last solution on that page) Is there a way to REGEXMATCH from a range of cells from A1:A1000 for example?
Say you want to search for a match from a list of cities.
Put your list of cities in one tab.
Make them into lowercase for easier lookup since search terms are all in lowercase. You can do this by adding a new column and using the LOWER function.
Go back to your cell that has the list of search phrases.
In any blank cell out of the way (off to the side on the top row is a good place) put this formula: CITY LIST FORMULA: =TEXTJOIN("|",1,'vlookup city'!B$2:B$477) (if your tab is named 'vlookup city' and your cities are in column B of that tab)
Add a new column next to your search terms, or pick an existing one where you want to put your "match found" info.
In that new column, add this formula (if your data starts in row 4 and you put the City List formula in cell G3:) =REGEXMATCH(A4,G$4)
Fill the formula all the way down your list. You can double-click the little blue square in the bottom right corner of the cell, or grab-and-drag all the way to the bottom of the list.
Ba-ding! It will search for any one of those city names, anywhere in your search phrase.
If the search phrase contains at least one matching term, it will return "True."
You can then add extra features on your formula to make it return something else. For example: =IF(REGEXMATCH(A4,G$4), "match found", "no match found")
This is a super lightweight solution that won't slow your sheet down too much and is easy to use.
https://docs.google.com/spreadsheets/d/1XAIDB98r2CGu7hL3ISirErDPNlgT6lVt-TCG0qI1uTE/edit?usp=sharing
The problem is that the Regexmatch solution identifies "Elvis Costello" and "Madonna Ford" and I only want to identify cells/rows that includes the exact term to match, ie "Elvis Presley" and "Madonna", ie whatever is between the commas has to be an exact match with one of the search terms, not just partially right.
I hope it made sense:)
Thanks all!
I think I might have found the answer, still trying to double check if it's correct.
I added \b before and after. So in the example sheet re-posted in the quoted part of my question i changed the cell:
Cell B3:
=TEXTJOIN("|",1,'vlookup city'!B$2:B$476)
and added another cell like this:
Cell B2:
=concatenate("\b(",$B$3,")\b")
Still checking if all false flags are removed.
Thanks

How do I count emoji and symbols in a cell?

What formula can I use to get a count of emoji and characters in a single cell?
For example, In cells, A1,A2 and A3:
๐Ÿ™Œ๐Ÿ™Œ๐Ÿ™Œ
๐Ÿคœโœ‹๏ธ๐Ÿ‘ˆ๐Ÿคœ๐Ÿคœ
??๐Ÿ‘Š๐Ÿ‘Š๐Ÿ‘Š
Total Count of characters in each cell(Desired Output):
3
5
5
For the given emojis, This will work well:
=LEN(REGEXREPLACE(A13,".","."))
MID/LEN considers each emoji as 2 separate characters.
REGEX will consider them as one.
But even REGEX will fail with a complex emoji like this:
๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ
This contains a literal man emoji๐Ÿ‘จ, a woman emoji๐Ÿ‘ฉ,a girl emoji๐Ÿ‘ง and a boy emoji๐Ÿ‘ฆ-all joined by a ZeroWidthJoiner. You could even swap the boy for a another girl with this formula:
=SUBSTITUTE("โ€๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ","๐Ÿ‘ฆ","๐Ÿ‘ง")
It'll become like this:
โ€๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ง
=COUNTA(FILTER(
SPLIT(REGEXREPLACE(A1,"(.)","#$1"),"#"),
SPLIT(REGEXREPLACE(A1,"(.)","#$1"),"#")<>""
))
Based on the answer by #I'-'I
Some emojis contain from multiple emojis joined by char(8205):
๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆโ€๐Ÿ‘ฆโ€๐Ÿ‘†
The result differs and depends on a browser you use.
I wonder, how do we count them?

Regular Expression to break row with comma separated values into distinct rows

I have a file with many rows. Each row has a column which may contain comma separated values. I need each row to be distinct (ie no comma separated values).
Here is an example row:
AB AB10,AB11,AB12,AB15,AB16,AB21,AB22,AB23,AB24,AB25,AB99 ABERDEEN Aberdeenshire
The columns are comma separated (Postcode area, Postcode districts, Post town, Former postal county).
So the above row would get turned into:
AB AB10 ABERDEEN Aberdeenshire
AB AB11 ABERDEEN Aberdeenshire
AB AB12 ABERDEEN Aberdeenshire
...
...
I tried the following but it didn't work...
(.+)\t(([0-9A-Z]+),)+\t(.+)\t(.+)
I agree that RegEx are not be the best way but this should work hopefully if that's all you have available to you. (Done repeatedly until there are no more matches)
Edit
Updated with the OP's final solution from the comments.
Find: (.+)\t([^,\s]+),([^\t]+)\t(.+)
Replace: \1\t\2\t\4\r\1\t\3\t\4
I agree with stakx that this doesn't sound like a good place for regexes.
I would write a small program instead which read each line, split the line into columns, split each relevant column into a list of values, and then iterated over all combinations of those, outputting a line each time.
Assuming it's only that one column which can have multiple tokens, it would basically look like this:
while not InputFile.EndOfFile:
line = InputFile.readline();
columns = line.split('\t'); //Assuming 1-based array, so indexes 1-4
col2values = columns[2].split(',');
for each value in col2values:
OutputFile.WriteLine(columns[1]+'\t'+value+'\t'+columns[3]+'\t'+columns[4]);
If multiple columns can have multiple values, simply put another loop inside the for each.