I want to combine multiple REGEXREPLACE in google sheet - google-sheets

I have a google sheet and in 'column A' I have list of fruit names. I want to find and replace 5 types of fruits with code names
"Mango" to be replaced with "001"
"Apple" to be replaced with "002"
"Orange" to be replaced with "003"
"Banana" to be replaced with "004"
"Jackfruit" to be replaced with "005"
I have a formula to replace just one of the word. Below is the formula
=ARRAYFORMULA(REGEXREPLACE(Sheet1!A:A, "Mango", "001"))
How do I combine the formula to replace all fruits with code words?

If it were me, I'd just use SWITCH:
=ArrayFormula(IFERROR(SWITCH(A:A,"mango","001","apple","002","orange","003","banana","004","jackfruit","005"),A:A))

Related

Google Sheets formula to merge multiple columns into one cell, including headers / label

I want to combine multiple columns in a Google sheet into one cell, including headers / labels. My input sheet looks like this:
Name
Description
Col 1
Col 2
Col 3
Foo
val 1
val 2
val 3
Bar
val x
val y
val z
And I want to concatenate the values in each column into a single cell, including the headers for each value. Desired output:
Name
Description
Foo
Col 1val 1Col 2val 2Col 3val 3
Bar
Col 1val xCol 2val yCol 3val z
This formula concatenates the columns into one, however it doesn't include the headers (note that char(10) produces a linebreak):
=TEXTJOIN(char(10),true,B2:E2)
I can produce a similar result using REDUCE (I can't believe I'm writing a reducer in a Google Sheet):
=REDUCE("", B2:E2, LAMBDA(accumulator, current_value, CONCATENATE(accumulator, current_value, char(10))))
However the lambda function doesn't seem to provide the index of the current iteration, so I'm not sure how to grab the column name above it.
Use this formula
=ARRAYFORMULA(
QUERY({"Description";
TRIM(SUBSTITUTE(FLATTEN(QUERY(TRANSPOSE(
IF(B2:D="",,","&B1:D1&","&B2:D&",")),"",9^9)),",",CHAR(10)))},
" Where Col1 is not null" ) )
try the old way:
=ARRAYFORMULA(TRIM(REGEXREPLACE(TRIM(FLATTEN(QUERY(TRANSPOSE(
IF(B2:D="",,"×"&B1:D1&"×"&B2:D&"×")),,9^9))), "×", CHAR(10))))
or in one cell if that's what you want:
=INDEX(TRIM(REDUCE(, B1:D1&CHAR(10)&B2:D3&CHAR(10),
LAMBDA(a, c, a&c&CHAR(10)))))
Using your current TEXTJOIN() formula you can just include the Column Headers with the dollar sign ($) which means absolute reference so it will not change when copied/dragged down to rows below.
Try:
=TEXTJOIN(char(10),true,C$1,C2,char(10),D$1,D2,char(10),E$1,E2)
Drag down to rows.
Result:
Refer to this link for more info on Absolute Reference: https://www.lido.app/tutorials/absolute-reference-on-google-sheets

To identify same words in two tabs in a google sheet

My Query is i want to highlight the duplicates in the two tabs in a sheet. My sheet is attached along with this question. In that "Sheet A" & "Sheet B" have common names in it i want to color it for the duplicates.
Sheet : https://docs.google.com/spreadsheets/d/1hL64Q7REorVkjJNKAEGPFBdinlIn8VwnE6H7L9fYB2c/edit#gid=0
If it is possible, is there any option to find the duplicates between two google sheets ?
if yes then pls help me to find duplicates in Sheet A in Match 1 sheet and Sheet C in Match 2 Sheet.
Sheet 2 : https://docs.google.com/spreadsheets/d/1xAUmvmaZPvfJwCHD_esrshLccgKM3VmP1CI46mMoRB8/edit#gid=0
I have an answer that shows how this can be done. See the tab I added, "Sheet 1-GK", into your sheet.
The formula in C1 looks at the data from Sheet 2 to see whether each name in Sheet 1 column A is found in Sheet 2.
Here is the primary formula:
=ARRAYFORMULA(IFERROR(
IF(MATCH(A2:A9,IMPORTRANGE("https://docs.google.com/spreadsheets/d/1xAUmvmaZPvfJwCHD_esrshLccgKM3VmP1CI46mMoRB8/edit","'SHEET C'!A$2:A$8"),0),
"Y",
"N"),
"N"))
In the sheet, I have wrapped it in an array, {...}, to also add the column header text.
Then a conditional formatting rule is used to highlight the rows that have "Y" in column C.
Note that you can either hide column C, or incorporate its formula logic into the conditional formating rule, to do everything there.
Is this what you were looking for, or did you need something else?

how to perform formatting in google sheets with text containing wildcard or "or" expression?

i want to perform format cells which contain characters "A" or "B" in google sheets
i have attempted "Text contains"
A,B
A|B
(A|B)
"A"|"B"
"A" or "B"
none of them work
or should i try "custom formula is"?
What should i do?
In the format rules choose 'custom formula' and then enter this formula
=regexmatch($B1;"A|B")
This should color the rows in the range B:C where the cells in column B contain A or B.
See if that works?

Google Sheets Dynamic Search Range

I am trying to get a dynamic search range. This is my current formula...
=ArrayFormula(COUNTIF(INDIRECT("B2:B"&row(), B2:B)))
I want to get a current count as you move down the sheet of how many times a string has been mentioned. For example, the word quote. The first row has the word quote. So in the "times mentioned" column C it should say 1. 5 rows later column B again says quote. Column C should say 2.
How do I get the formula to recognize the first row to be B2:B2 and the second occurrence in row 5 to B2:B5?
You might try, in Row1:
=ArrayFormula(if(row()<=countif(B:B,"quote"),Row(),""))
copied down to suit.
EXACT MATCH:
dynamic with helping column:
B1: =ARRAYFORMULA(IF(A1:A="quote", 1, ))
C1: =ARRAYFORMULA(IF(B1:B="", , SUMIF(ROW(B1:B), "<="&ROW(B1:B), B1:B)))
PARTIAL MATCH:
B1: =ARRAYFORMULA(IF(IFERROR(REGEXEXTRACT(A1:A, "quote"))="quote", 1, ))
C1: =ARRAYFORMULA(IF(B1:B="", , SUMIF(ROW(B1:B), "<="&ROW(B1:B), B1:B)))

Categorize cells by keywords

I am not certain if excel can do this but I am trying to simplify the data dump that I get from twitter.
Basically what I would like to do is this:
If the tweet (in Column A) contains apple OR orange OR pear then it can be classified (in Column B) as "fruit" BUT if it has carrot OR squash OR lettuce it will be classified as "vegetable". If it has none of these then can be classified as "none"
Is this possible?
Thanks in advance.
Here is using array constant and range.
=IF(SUMPRODUCT(IF(ISERROR(SEARCH({"apple","orange","pear"},A1)),0,1))>0,"Fruit",IF(SUMPRODUCT(IF(ISERROR(SEARCH({"carrot","squash","lettuce"},A1)),0,1))>0,"Vegetable","None"))
Now for example, both fruit and vegetable are present in a string, it will always test for fruit first since that is the way the formula was arranged. (e.g. "more apple on salad than lettuce" will return "Fruit").
You can also use a range that contains your list instead of the array constant.
For example, you can put your fruit list in Column C (C1:C3) and your vegetable list in Column D (D1:D3). Your formula would then be:
=IF(SUMPRODUCT(IF(ISERROR(SEARCH(C$1:C$3,A1)),0,1))>0,"Fruit",IF(SUMPRODUCT(IF(ISERROR(SEARCH(D$1:D$3,A1)),0,1))>0,"Vegetable","None"))
But you need to enter it as Array Formula using Ctrl+Shift+Enter.
Same results and rule apply when both fruit and vegetable appear on a string. HTH.
Sure.
Try this formula
=IF(
OR(
NOT(ISERROR(SEARCH("apple",A1))),
NOT(ISERROR(SEARCH("pear",A1))),
NOT(ISERROR(SEARCH("orange",A1)))
),
"fruit",
IF(
OR(
NOT(ISERROR(SEARCH("carrot",A1))),
NOT(ISERROR(SEARCH("squash",A1))),
NOT(ISERROR(SEARCH("lettuce",A1)))
),
"veggie",
"none"
)
)

Resources