Is there code that can force a user to enter a particular format into a cell? - google-sheets

I have a Google Spreadsheet.
Google Spreadsheet
When users enter a name into any cell of column A of the sheet named "Unit Standards" I want them to enter that name in a particular format. That is, with the surname first in uppercase then a comma, then the first name in title case then if they are known by a different name that name to be title case in brackets e.g.
BUSH, George
TRUMP, Donald
CLINTON, William (Bill)
CARTER, James (Jimmy)
SMITH-JONES, John
ZETA-JONES, Catherine (Kate)
Is there a way to force them to do that before they leave the cell or the sheet?

You could use a script. Still.
You can have the same results with a simple formula using Data Validation on column A.
This is the formula to put in cell A2 for the range A2:A555:
=REGEXMATCH(A2,"^[A-Z]+\b[',']\s[A-Z]{1}[a-z]+\b(\s([A-Z][a-z]+\b))?$")
Reading the regular expression:
^[A-Z]+\b[',']\s[A-Z]{1}[a-z]+\b(\s([A-Z][a-z]+\b))?$
^[A-Z]+\b: In the beginning have only 1 or more capital letters until the end of the word
[',']\s: Have a , followed by an empty space
[A-Z]{1}[a-z]+\b: Have only 1 capital letter and 1 or more small letters till the end of the word
(\s\([A-Z][a-z]+\b\))?$: All of the above could be followed ? by this string.
\s\(: An empty space and an opening parenthesis (
[A-Z][a-z]+\b: A word starting with just 1 capital followed by 1 or more small letters
\): A closing parenthesis
$: End of string

Related

Is there a function in Google Sheets to return the string next to a string that I match from a column of strings?

Okay, Sheet1!F:F is a list of words in English. The same word occurs multiple times and the sheet is organized in order of chapters with the words in question in order as they appear in the chapter. "G:G needs to be that word in Arabic. "H:H needs to be the definition in English. "I:I needs to be the definition in Arabic.
Sheet2!A:A has the word in English, B:B the word in Arabic, C:C the definition in English, D:D the definition in Arabic.
Is there a function that would allow me to find the word from Sheet1!F:F in Sheet2!A:A and return Sheet2!B:B in Sheet1!G:G?
Here's some snipits of an example sheet.
Sheet1!
Sheet2!
You want to find the "Word AR" Sheet1 column G in "Word AR" Sheet2 column B, in other word find the arabic word for the English word from another table.
Paste this formula in Sheet1 cell G2, and drag it down.
=IF(F2="",,INDEX(Sheet2!$B$2:$B,IFNA(MATCH(F2,Sheet2!$A$2:$A,0),"No Match")))
Breakdown:
1 - MATCH function to find the matching row in the range Sheet2!$A$2:$A with [search_type] set to 0 to finds the exact value when range is unsorted.
2 - INDEX gives back a cell's content from a range when given a row and column, our reference is Sheet2!$B$2:$B we set the [column] as 1 or left it blank in case of a single column and pass the result of MATCH function as [row].
3 - handel N/A error with IFNA function and set [value_if_na_error] to "No Match".
4 - IF function IF(F2="",,[value_if_false] To calculate only when the cells of F columns are not blank.
hope that answers your question.
One option would be to use a VLOOKUP formula. For example:
=ifna(arrayformula(vlookup(A2:A, Sheet2!A2:D, 2,0)))
Sheet1:
Sheet2:
This formula can be adjusted to fit your needs:
=ifna(arrayformula(vlookup(F3:F, Sheet2!A2:D, 2,0)))
This can be placed in cell G3 of your Sheet1 and it will auto fill down the column. Repeat this for the next 3 columns, and simply increment from 2 in the original (ie =ifna(arrayformula(vlookup(F3:F, Sheet2!A2:D, 3,0))), etc)

ArrayFormula, RegexExtract, and Join in Google Sheets

I have a data set wherein emails are populated. I would like to list all the surnames extracted in the emails per cell and will be all joined to a one single cell but I want to put a separator or delimeter to the emails obtaine per cell.
Here is the data set:
A
B
john.smith#gmail.com, jane.doe#gmail.com
UPDATE
john.smith#gmail.com
CLOSE
And here is the formula to extract
=ARRAYFORMULA(
PROPER(
REGEXEXTRACT(
A:A,
REGEXREPLACE(
A:A,
"(\w+)#","($1)#"
)
)
)
)
This initially yields the ff:
C
D
Smith
Doe
Smith
I would like to use JOIN() inside the ARRAYFORMULA() but it is not working as I seem to think it would since it outputs an error that it only accepts one row or one column of data. My initial understanding of ARRAYFORMULA() is that it iterates through the course of the data, so I thought it will JOIN() first, and then move on to the next element/row but I guess it doesn't work that way. I can use FLATTEN() but I want to have delimiters or separators in between the row elements. I need help in obtaining my intended final result which will look like this:
UPDATE:
Smith
Doe
CLOSE:
Smith
All are located in one cell, C1. UPDATE and CLOSE are from column B.
EDIT: I would like to clarify that the email entries in column A are dynamic and maybe more than two.
I think this will work:
=arrayformula(flatten(if(A2:A<>"",regexreplace(trim(split(B2:B&":"&char(9999)&regexreplace(Proper(A2:A),"#[\w\.]+,\ ?|#.*",char(9999)&" "),char(9999))),".*\.",),)))
NOTES:
Proper(A2:A) changes the capitalisation.
The regexreplace "#[\w\.]+,\ ?|#.*" finds:
# symbol...
then any number of A-Z, a-z, 0-9, _ [using \w] or . [using \.]
then a comma
then 'optionally' a space \ [the optional bit is ?]
or [using |], the # symbol then an number of characters [using .*]
The result is replaced with a character that you won't expect to have in your text - char(9999) which is a pencil icon, and a trailing space (used later on when the flatten keeps a gap between lines). The purpose is to get all of the 'name.surname' and 'nameonly' values in front of any # symbol and separate them with char(9999).
Then infront of the regexreplace is B2:B&":"&char(9999)& which gets the value from column B, the : chanracter and char(9999).
The split() function then separates then into columns. Trim() is used to get rid of spaces in front of names that don't contain ..
The next regexreplace() function deletes anything before, and including . to keep surname or name without ..
The if(A2:A<>"" only process rows where there is a value in col A. The arrayformula() function is required to cascade the formula down the sheet.
I didn't output the results in a single cell, but it looks like you've sorted that with textjoin.
Here's my version of getting the results into a single cell.
=arrayformula(textjoin(char(10),1,if(A2:A<>"",REGEXREPLACE(B2:B&":"&char(10)&regexreplace(Proper(A2:A),"#[\w\.]+,\ ?|#.*",char(10)),".*\.",),)))
Assuming that your A:A cells will always contain only contiguous email addresses separated by commas, you could place this in, say, C1 (being sure that both Columns C and D are otherwise empty beforehand):
=TRANSPOSE(FILTER({B:B,IFERROR(REGEXEXTRACT(SPLIT(PROPER(A:A),","),"([^\.]+)#"))},A:A<>""))
If this produces the desired result and you'd like to know how it works, report back. The first step, however, is to make sure it works as expected.
use:
=INDEX(REGEXREPLACE(TRIM(QUERY(FLATTEN(QUERY(TRANSPOSE({{B1; IF(B2:B="",,"×"&B2:B)},
PROPER(REGEXEXTRACT(A:A, REGEXREPLACE(A:A, "(\w+)#", "($1)#")))})
,,9^9)),,9^9)), " |×", CHAR(10)))

Google Sheets Match Any Text

In Google Sheets, I have 2 columns (A and B) of text and I'm trying to set up conditional formatting to identify partial duplicates for when these 2 criteria are both met:
Text in A exactly matches with any other cell in A
and
Any of the individual words in cell B match any of the words in any other cell in B
So, if A2 = "target.com" and B2 = "Big Bonus"
I want it to flag any other cells where A = "target.com" and B = "Bonus Donuts" or "Biggest Exciting Bonus Ever" (because "Bonus" is identified as the duplicate) or "Exciting Big Day" (because "Big" is identified as the duplicate). I need it to be case-agnostic.
Nothing I have tried has even come close to working, so I won't include any of it here.
Sample Data: https://docs.google.com/spreadsheets/d/1DO-0uJRf6MOJ7fJiza5MAmFNIqpCwJ4WMH28j6wp22w/edit#gid=0
I've added a new sheet ("Erik Help") to your sample spreadsheet, with the following custom CF rule applied to the range A3:B ...
=AND($A3=$A$1, REGEXEXTRACT(LOWER($B3),SUBSTITUTE(TRIM(LOWER($B$1))," ","|")))
$A3=$A$1 should be self-explanatory.
For the rest, you see I used LOWER to make the comparisons caps-agnostic. I applied TRIM, just in case you accidentally added any spaces into the B1 string and then just replaced remaining spaces with the pipe symbol, which is interpreted by REGEXEXTRACT as OR.
If you don't want partial word matching (Big in Biggest), try this in the conditional custom formula:
=and($A3=$A$1, regexextract(" "&lower($B3)&" "," "&substitute(lower($B$1)," "," | ")&" "))

How to remove REGEXEXTRACT #N/A error and ignore special characters in Google Sheet?

Let's say I have column A:A containing titles. In another column I want to show the first letter of title, ignoring special characters, like so:
Title
Chapter
(A) Title
A
Title
T
This is an array formula put on B1 I made so far, but not working properly as my example above:
=ARRAYFORMULA(if(row(A:A)=1,"Chapter",REGEXEXTRACT(A:A,".")))
It contains an error message #N/A on every row if column A doesn't have text. It also shows a special character if it begins with. This is how it currently looks:
Title
Chapter
(A) Title
(
Title
T
#N/A
#N/A
Any ways to fix this?
Also try the simpler
=ArrayFormula({"Title ";
IFERROR(REGEXEXTRACT(B2:B,"\w"),)})
(do adjust ranges to your needs)
See if this helps
={"Chapter"; ArrayFormula(left(regexreplace(A2:A, "[^A-Za-z]*",), 1))}

Count occurrences of a specific word in Google Spreadsheet

I have some cells with text. I need to count the occurrences of a specific word (not a list) from those cells.
Example sheet:https://docs.google.com/spreadsheets/d/1WECDbepLtZNwNfUmjxfKlCbLJgjyUBB72yvWDMzDBB0/edit?usp=sharing
So far I found one way to count it in English by using SUBSTITUTE to replace all these words with "":
=(LEN(B1)-LEN(SUBSTITUTE(UPPER(B1),UPPER(A5),"")))/LEN(A5)
However, I don't know why but it doesn't work in German.
Edited:
I don't want to count "Hero" in "Heroes". However, I'd like to count "afk" in "AFK-Spiel" (German for example). Is it possible?
If you want to count occurences of "Hero" word
=COUNTIF(SPLIT(JOIN(" ", B1:B3), " -."&CHAR(10)), "Hero")
Where:
B1:B3: cells with text
"Hero": the word to count
Explaination
JOIN(" ", B1:B3): Concatenation of all cells with text
SPLIT(..., " -."&CHAR(10)): Create an array with each words
COUNTIF(..., "Hero"): Count each array item equals to "Hero"
Example
if input text is:
Hero Hero-666 heroes heroic
➔ then formula will return 2.
If you want to count occurences of "Hero" string
(Even nested in an other word, i.e: "Heroes")
=COUNTA(SPLIT(UPPER(JOIN(" ",B1:B3)), "HERO", false, false))-1
Where:
B1:B3: cells with text
"HERO": the string to count
Explaination
JOIN(" ", B1:B3): Concatenation of all cells with text
UPPER(...): Convert text in upper case
SPLIT(..., "HERO"): Split on each occurences of the string
COUNTA(...)-1: Count how many splits have been done
Example
if input text is:
Hero Hero-666 heroes heroic
➔ then formula will return 4.
In your sheet you mention that the count should be 14.
Considering that, I believe you are looking for a solution to also include words like heroes or Hero
If you want to include variations of hero, like Hero or Heroes you can use the following:
Case insensitive for any language formula:
=COUNTIF(SPLIT(CONCATENATE(B1:B3), " "), "*heRO*")
You can even have *heRO* placed in a cell like A7 and use
=COUNTIF(SPLIT(CONCATENATE(B1:B3), " "), A7)
If you want just the word Hero, remove the asterisks * around it.
It also works for any language (including German).
try:
=ARRAYFORMULA(COUNTA(IFERROR(SPLIT(QUERY(SUBSTITUTE(
UPPER(B1:B3), UPPER(A5), "♦"),,99^99), "♦")))-1)
and for german:
=ARRAYFORMULA(COUNTA(IFERROR(SPLIT(QUERY(SUBSTITUTE(
UPPER(C1:C3), "HELD", "♦"),,99^99), "♦")))-1)

Resources