I have a Google Spreadsheet doc with two columns:Column A and Column B.
I need formula in Column B to get the value in Column A with the sign '+' prepended for each word.
Take a look at the capture:
Try this formula in cell B1:
=ArrayFormula(IF(A:A="",,SUBSTITUTE("+"&A:A," "," +")))
This formula also works:
=JOIN(" +",SPLIT(A1," "))
Regexreplace also good thing to make it with condition:
=ArrayFormula(IF(A:A="",,REGEXREPLACE(A:A,"(\w{4,})"," +$1")))
to add + only for words which has more than 3 characters
Related
I'm new to google sheet. I have a column(E) with the date and another with a session(F), I want to merge them into one column with each date & different session just like the first few rows in column C.
I've tried "=ArrayFormula(concat(D2:D,concat(" ",F2:F5)))" in column C but only got the first date.
use:
=INDEX(QUERY(FLATTEN(FILTER(E2:E, E2:E<>"")&" "&
TRANSPOSE(FILTER(F2:F, F2:F<>""))), "where not Col1 starts with ' '", ))
see: https://stackoverflow.com/a/68775825/5632629
In your cell C1, try this formula:
=ArrayFormula(E1:E&" "&F1:F)
Well you can simply do concatenate cells like this:
CONCATENATE(E1, " ", F1)
to get what you want I think.
What you're looking for is a cartesian product. I don't have a single formula that does the entire thing for you, but I can suggest a two-step approach.
Get the cartesian product with this formula:
=ARRAYFORMULA(SPLIT(FLATTEN(E2:E9 & "|" & TRANSPOSE(F2:F5)), "|"))
This gives a pair of each date against each time in two result columns. You can then concatenate each row of them in a final result column.
Here is a screenshot of and a link to my test spreadsheet. It makes the requirements very clear:
https://docs.google.com/spreadsheets/d/1rZr2zHaSkff9SFpwpx83_4TawruotA1jhOKqW6uYDz0/edit?usp=sharing
The formula I have come up with is very close to what I need, but "linkText" is a placeholder for the value of the array item. Here is my formula:
=if(A2="","","<a href='https://samplewebsite.com/search?q=" & trim(lower(substitute(A2,",","'>linkText</a>, <a href='https://samplewebsite.com/search?q="))) & "'>linkText</a>")
try:
=index(join(","&char(10), SUBSTITUTE($B$1, "linkText", split(A3, ","))))
Drag down to column.
Result:
First using SPLIT to split the strings between comma from the column A. Then using SUBSTITUTE to find the string "linkText" from the text in B1 and replace it with the strings from the returned strings from the split function. Then joining them all together.
NOTE: Just keep the reference string in a fixed cell in your sheet. <a href='https://samplewebsite.com/search?q=linkText'>linkText</a> to be used in the formula. As seen in above screenshot it is fixed in cell B1.
Alternate Solution using ArrayFormula:
You can also use it with arrayformula so you only have to put it in the first row and no need to drag down the formula to the column, it will automatically be expanded down just make sure to clear the cells below or it will throw an error.
=arrayformula(regexreplace(substitute(transpose(query(transpose(IF(IFERROR(SPLIT(A2:A, ","))<>"", "♦<a href='https://samplewebsite.com/search?q="&SPLIT(A2:A, ",")&"'>"&SPLIT(A2:A, ",")&"</a>", )),,9^9)), "♦", char(10)), "^\s", ""))
Result:
You may also have a look in below references for more information.
References:
SUBSTITUTE
SPLIT
JOIN
Comma separated list into matched columns pairings
I'm trying to use regex to remove numbers from Column C using the formula below. it works for one cell but not for multiple. I want to apply the formula to the whole c column starting from C7
=REGEXREPLACE(C7:C, "[0-9]*\.[0-9]|[0-9]","")
Any advice?
use:
=INDEX(REGEXREPLACE(C7:C, "[0-9]*\.[0-9]|[0-9]", ))
Nearly found the answer here: First non blank cell in row as an array for the column But this formula only returns the first word of each cell.
Here's my example sheet
COLUMN M is the copied formula from the above stackoverflow answer.
The only way I can get the result I need is by duplicating the formula using '&', adding a space (" ") and TRIM() at the beginning as it adds additional spaces.
Is there any way of simplifying my formula in COLUMN N?
I added a new sheet ("Erik Help") with the following formula in M1:
=ArrayFormula({"Header of Choice";IF(A2:A="",,TRIM(TRANSPOSE(QUERY(TRANSPOSE(B2:L)," ",COLUMNS(B2:L)))))})
As I see it, this is about as concise, flexible and powerful as the formula can get. It takes advantage of a quirk in how QUERY headers are handled.
This formula can handle any number of words in a cell. Of note, it assumes (as shown in your sheet) that there will only be one string to return per row in B:L. If there will be more than one possible return per row, the formula can be easily modified to include a delineator.
shorter:
={"SHORT FX"; INDEX(IF(A1:A="",,TRIM(
IFERROR(INDEX(SPLIT(TRIM(FLATTEN(QUERY(TRANSPOSE(B2:L),,9^9))), " "),,1))&" "&
IFERROR(INDEX(SPLIT(TRIM(FLATTEN(QUERY(TRANSPOSE(B2:L),,9^9))), " "),,2))&" "&
IFERROR(INDEX(SPLIT(TRIM(FLATTEN(QUERY(TRANSPOSE(B2:L),,9^9))), " "),,3))
)))}
UPDATE:
={"SHORTEST"; INDEX(IF(A2:A="",,TRIM(FLATTEN(QUERY(TRANSPOSE(B2:L),,9^9)))))}
I'm using the query function in google sheets... I want to select columns F to AB.
I need a cell that has the output F,G,H,I... ,AB so I can put it in the Select statement.
This formula should have 2 inputs, the starting letter (F in this case) and number of following columns (22 in this case)
No app script code please. I know someone can do it with just formulas in one cell.
I believe your goal as follows.
You want to create the value of F,G,H,I... ,AB by giving the start column letter of "F" and the number of columns of 22.
For example, when the start column letter of "F" and the number of columns of 22 are given, you want to retrieve the value of F,G,H,I... ,AB and you want to use this like =QUERY(A1:AB,"SELECT F,G,H,I... ,AB").
You want to achieve this using the built-in functions of Google Spreadsheet without the Google Apps Script.
For this, how about this answer?
Sample formula 1:
In this sample formula, in order to create the value of F,G,H,I... ,AB by giving the start column letter of "F" and the number of columns of 22, I would like to propose the following formula.
=TEXTJOIN(",",TRUE,ARRAYFORMULA(REGEXREPLACE(ADDRESS(1,COLUMN(INDIRECT(A1&"1:"&ADDRESS(1,B1+COLUMN(INDIRECT(A1&"1")),4))),4),"\d+","")))
When A1 and B1 have the values of F and 22, respectively, the flow of this formula is as follows.
Using COLUMN, retrieve the column numbers.
Using ADDRESS, retrieve the column letters from the column numbers. At that time, the row number os removed using REGEXREPLACE.
Above formulas are used with ARRAYFORMULA.
Using TEXTJOIN, join the column letters with ,.
Result:
Sample formula 2:
In this sample formula, =QUERY(A1:AB,"SELECT F,G,H,I... ,AB") is created using above sample formula 1.
=QUERY(A1:AB,"SELECT "&TEXTJOIN(",",TRUE,ARRAYFORMULA(REGEXREPLACE(ADDRESS(1, COLUMN(INDIRECT(A1&"1:"&ADDRESS(1, B1 + COLUMN(INDIRECT(A1&"1")), 4))), 4),"\d+",""))))
Result:
In this sample result, the range of A2:AB7 is used for QUERY. So please be careful this. When the cells "A1" and "B1" are changed, the result of this formula is also changed.
Note:
In this case, when the start column and the number of columns are more than the existing maximum columns, an error occurs, please be careful this.
References:
COLUMN
ADDRESS
REGEXREPLACE
ARRAYFORMULA
TEXTJOIN
Added:
When you want to create Col6, Col7, Col8 ... Col28 by giving the start column letter of "F" and the number of columns of 22, how about the following sample formula?
Sample formula:
="Col"&TEXTJOIN(",Col",TRUE,ARRAYFORMULA(COLUMN(INDIRECT(A1&"1:"&ADDRESS(1,B1+COLUMN(INDIRECT(A1&"1")),4)))))
In this case, please put F and 22 to the cells "A1" and "B1", respectively.
if your range is F:AB then you can skip select parameter or use:
=QUERY(F1:AB; "select *"; 0)
if the range is larger put the range in curly brackets and try:
=ARRAYFORMULA(QUERY({A1:AB}; "select "&TEXTJOIN(","; 1; "Col"&COLUMN(F:AB)); 0))