Google Sheets IF (in multiple cells) text contains, then return the text - if-statement

Please help!
If A2, B2, or C2 contains text (ANY TEXT... nothing specific), then return the text of that cell in D2.
I've tried several things, but I cannot get it to work.

If more than one contains text what should happen??
With =IFNA(FILTER(A2:C2,ISTEXT(A2:C2))) you can search through them and then join them with =TEXTJOIN(", ",1,IFNA(FILTER(A2:C2,ISTEXT(A2:C2))))
If you need it as an array, you can do:
=BYROW(A2:C,LAMBDA(each,TEXTJOIN(", ",1,IFNA(FILTER(each,ISTEXT(each))))))

use in cell D2:
=A2&B2&C2
you can add spaces if you need:
=TRIM(A2&" "&B2&" "&C2)

Related

Conditional Formatting Cells in a Column Only Containing Letters F-Z Excluding RR

How could I highlight cells using conditional formatting if I want to only highlight cells containing letters F-Z? The formula would also need to exclude RR.
For example, if a cell in that column contains RR or any letter from A to E, I don't want to highlight it. But, if it contains any letter from F all the way to Z, I want it automatically highlighted.
Tried using regexmatch, but it's not working.
use:
=REGEXMATCH(A2, "[F-Z]")*(REGEXMATCH(A2, "RR")=FALSE)

Find a partial string in a cell and return exact value using a formula?

I need some help on this. I would like to find two different partial strings in a cell using a formula.
For example - if cell (A1) contains "Staples A-12345 Georgia, USA" or other cell may contain only "g345" or "g100, g000" or other times it contains both A-12345 g345 in a cell as an example.
My goal is to return a value of "GXXX" or if not present, use the "A-XXXXX".
Search A1 cell for partial text of "A-" or "G". (The "A-, must contain 7 characters" and "G, must contain 4 characters.)
If true, C1 to return value of GXXX or if that is not present, use the other one.
If it contains multiple codes (GXXX, GXXX) then return both values separated with a comma
If it contains both "A-" and "G" in a cell, grab only the "G" code.
If cell blank, return blank value.
If cell value does not contain both "GXXX" or "A-XXXXX", copy and return the same value.
I am currently using this formula. I am unable to display the actual string.
=IFS(
ISNUMBER(SEARCH("*A-*",A1)),"TRUE",
ISNUMBER(SEARCH("*G*",A1)),"TRUE")
I got confused and stuck on this.Your time and help is greatly appreciated. Thank you.
use:
=IFNA(IF(A1="",,
IF(REGEXMATCH(A1, "(g\d{3}).*(g\d{3})|(g\d{3})"), TEXTJOIN(", ", 1,
REGEXEXTRACT(A1, "(g\d{3}).*(g\d{3})|(g\d{3})")), REGEXEXTRACT(A1, "A-\d{5}"))), A1)

Filter with REGEXMATCH in Google sheet to filter out containing text in cells

Right now I have these data and I'm trying to filter out the data containing in cell C3, C4, etc.
I have no problem filtering the regexmatch data for 1 cell as shown below
but I'm unable to do regexmatch for more than 2 cells like so for example, it seems like I'm unable to make the pipework between cells as I'll get parse error, I tried adding in "C3|C4" too.
and
The wanted output that I wanted is as below but I could only hardcode the containing text in which isn't what I'm looking for. I'm hoping that I could have some tips to regexmatch the text in more than 1 cell such that it could regexmatch the text in cell C3(Apple) and C4(Pear) and show the wanted output.
you need to use TEXTJOIN for dynamic list in C column:
=IF(TEXTJOIN( , 1, C3:C)<>"", FILTER(A2:A, REGEXMATCH(LOWER(A2:A),
TEXTJOIN("|", 1, LOWER(C3:C)))), "no input")
You may use
=IF(C3<>"", FILTER(A2:A,REGEXMATCH(A2:A, TEXTJOIN("|", TRUE, C3:C4) )), "no input")
Or, you may go a step further and match Apple or Pear as whole words using \b word boundaries and a grouping construct around the alternatives:
=IF(C3<>"", FILTER(A2:A,REGEXMATCH(A2:A, "\b(?:" & TEXTJOIN("|", TRUE, C3:C4) & ")\b")), "no input")
And if you need to make the search case insensitive, just append (?i) at the start:
=IF(C3<>"", FILTER(A2:A,REGEXMATCH(A2:A, "(?i)\b(?:" & TEXTJOIN("|", TRUE, C3:C4) & ")\b")), "no input")
See what the TEXTJOIN documentation says:
Combines the text from multiple strings and/or arrays, with a specifiable delimiter separating the different texts.
So, when you pass TRUE as the second argument, you do not have to worry if the range contains empty cells, and the regex won't be ruined by extraneous |||.
Test:

Google Sheets formula to add case-insensitive text + text in cell

I have some text on row A, and I want to write on cell E1 to filter whenever I put this formula
=Filter(A1:A10;ArrayFormula(E1 REGEXMATCH(A1:A10;E1)))
but I want it to CONTAINS not EXACT text
=filter(A1:A10;REGEXMATCH(A1:A10;"(i?) TEX"))
This works but I want to add a cell value
so somehow to combine this to together
I'm trying to put value in cell E1 (?i)TEX and it finds TEXT on A row, but I want to put (?i) in the formula but can't find how to do it.
I tried
=Filter(A1:A10;ArrayFormula(E1 REGEXMATCH(A1:A10;"(i?) +"E1"")))
doesn't work
=Filter(A1:A10;ArrayFormula(E1 REGEXMATCH(A1:A10;"(i?)"+E1)))
doesn't work
=filter(A1:A10;REGEXMATCH(A1:A10;"(i?)&" "&E1"))
doesn't work
I really don't have an idea of how to add (i?) to cell value
To make a match case-insensitive you'll need (?i) instead of (i?). I believe this should work
=filter(A1:A10;REGEXMATCH(A1:A10; "(?i)"&E1))

How can I separate a string by underscore (_) in google spreadsheets using regex?

I need to create some columns from a cell that contains text separated by "_".
The input would be:
campaign1_attribute1_whatever_yes_123421
And the output has to be in different columns (one per field), with no "_" and excluding the final number, as it follows:
campaign1 attribute1 whatever yes
It must be done using a regex formula!
help!
Thanks in advance (and sorry for my english)
=REGEXEXTRACT("campaign1_attribute1_whatever_yes_123421","(("&REGEXREPLACE("campaign1_attribute1_whatever_yes_123421","((_)|(\d+$))",")$1(")&"))")
What this does is replace all the _ with parenthesis to create capture groups, while also excluding the digit string at the end, then surround the whole string with parenthesis.
We then use regex extract to actuall pull the pieces out, the groups automatically push them to their own cells/columns
To solve this you can use the SPLIT and REGEXREPLACE functions
Solution:
Text - A1 = "campaign1_attribute1_whatever_yes_123421"
Formula - A3 = =SPLIT(REGEXREPLACE(A1,"_+\d*$",""), "_", TRUE)
Explanation:
In cell A3 We use SPLIT(text, delimiter, [split_by_each]), the text in this case is formatted with regex =REGEXREPLACE(A1,"_+\d$","")* to remove 123421, witch will give you a column for each word delimited by ""
A1 = "campaign1_attribute1_whatever_yes_123421"
A2 = "=REGEXREPLACE(A1,"_+\d*$","")" //This gives you : *campaign1_attribute1_whatever_yes*
A3 = SPLIT(A2, "_", TRUE) //This gives you: campaign1 attribute1 whatever yes, each in a separate column.
I finally figured it out yesterday in stackoverflow (spanish): https://es.stackoverflow.com/questions/55362/c%C3%B3mo-separo-texto-por-guiones-bajos-de-una-celda-en...
It was simple enough after all...
The reason I asked to be only in regex and for google sheets was because I need to use it in Google data studio (same regex functions than spreadsheets)
To get each column just use this regex extract function:
1st column: REGEXP_EXTRACT(Campaña, '^(?:[^_]*_){0}([^_]*)_')
2nd column: REGEXP_EXTRACT(Campaña, '^(?:[^_]*_){1}([^_]*)_')
3rd column: REGEXP_EXTRACT(Campaña, '^(?:[^_]*_){2}([^_]*)_')
etc...
The only thing that has to be changed in the formula to switch columns is the numer inside {}, (column number - 1).
If you do not have the final number, just don't put the last "_".
Lastly, remember to do all the calculated fields again, because (for example) it gets an error with CPC, CTR and other Adwords metrics that are calculated automatically.
Hope it helps!