in Google Sheets using formulars I would like to build an array of the columns that fulfills a simple criteria, so for example:
A
B
C
D
E
F
G
h1
h2
h2
h1
h3
h2
h1
Then I would like to have the array {A:A,D:D,G:G} if I search for 'h1'
I suppose what you want is to get the Column letter of the cell if some criteria is met. Like :"what colums have the right answer?" and the return that letter in some way.
So as far as i know sheets does not provide that as a simple function. (But im not very skilled in sheets).
Heres a hacky thing that might work for you:
Somwhere in your sheet (eg bottom row # 100 make cells that hold your letters
So A100 holds "A" or "A:A" B100 holds "B" or "B:B" and so forth.
then you can use filter function.
If the row you want to want to investigate is the first:
code:
=FILTER(A100:Z100;A1:Z1="h2")
that will give you your array.
Cheers Mads
Suppose your raw data is in a sheet named Sheet1.
In a new sheet (e.g., Sheet2), place the following formula in A1:
=IFERROR(FILTER(Sheet1!A:G,Sheet1!A1:G1="h1"))
You could also place this version of the formula in Sheet2 cell B1:
=IFERROR(FILTER(Sheet2!A:G,Sheet2!A1:G1=A1))
... and then enter "h1" (or some other text to match) into cell A1.
ADDENDUM (after further comment from OP):
=IFERROR(FILTER(REGEXREPLACE(ADDRESS(1,COLUMN(Sheet2!A:G),4)&":"&ADDRESS(1,COLUMN(Sheet2!A:G),4),"\d",""),Sheet2!A1:G1="h1"))
heres a pice of code that will give you the column letter for any column.
Maybe you can use this in your code, or you can paste it in a cell and copy drag vertically it to get the column letters, like i sugested in previous post.
=IF(TRUNC((column()-1)/26)<1;CHAR((MOD((column()-1);26))+65);CHAR(TRUNC((column()-1)/26)+65)&CHAR((MOD((column()-1);26))+65))
Good Luck :)
Related
So I have two rows:
ID
TagDog
TagCat
TagChair
TagArm
Grouped Tags (need help with this)
1
TRUE
TRUE
TagDog,TagArm
Row 1 consists mainly of Tags, while rows 2+ are entries. This data ties ENTRIES to TAGS.
What I'm needing to do is concatenate/join the tag names per entry. For example, look at the last column above.
I suspect we could write a formula that would:
Create an array of non-empty cells in the row. (IE: [2,4])
Return it with the header row A (IE: [A2,A4])
Then join them together by a comma
But I am unsure how to write the formula, or if this is even the best approach.
Here's the formula:
={
"Grouped Tags (need help with this)";
ARRAYFORMULA(
REGEXREPLACE(TRIM(
TRANSPOSE(QUERY(TRANSPOSE(
IF(NOT(B2:E11),, B1:E1)
),, COLUMNS(B1:E1)))
), "\s+", ",")
)
}
The trick used is called vertical query smash. That's the part:
TRANSPOSE(QUERY(TRANSPOSE(...),, Nnumber_of_columns))
You can find a brief description of this one and his friends here.
I wasn't able to create a single formula that would do this for me, so instead, I utilized a formula inside of Sheets' Find/Replace tool, and it worked like a charm!
I did a find/replace, replacing all instances of TRUE with the following formula:
=INDIRECT(SUBSTITUTE(LEFT(ADDRESS(ROW(),COLUMN()),3),"$","")&"$1")
What this formula does is it finds the cell's letter, then gets the first row of the cell using INDIRECT.
Breaking down the formula:
ADDRESS(ROW(),COLUMN()) returns the direct reference: $H$1
LEFT("$H$1",3) returns $H$
SUBSTITUBE("$H$","$","") replaces the dollar signs ($) and returns H
INDIRECT(H&"$1") references the exact cell H$1
Now, I can replace all instances of TRUE with that formula and the magic happens!
Here is a video explanation: https://youtu.be/SXXlv4JHDA8
Hopefully, that helps someone -- however, I would still be interested in seeing what the formula is for this solution.
I have a spreadsheet where in every column I have a list of names. They can repeat, and whats even worse - cells can contain some additional text (apart from the name).
What I want to do is count the occurrences of the name in the whole spreadsheet (only looking at the name, omitting the potential additional text). Is Possible?
I tried the formula =UNIQUE, but it does not work vertically (I'm working with Google Sheets)
Example of a document https://docs.google.com/spreadsheets/d/1STtJr0yisSeuv2w8_JVgQABAL5EDzI8aFmH8Vp2cOko/edit?usp=sharing
You can use Countif, Arrayformula, and Regexreplace to accomplish this task
Assuming you have the data range from A2:E12 and the prefilled unique names starting from A14
Formula:
=countif(ARRAYFORMULA(regexreplace($A$2:$E$12,".\(.*","")),A14)
Copy the formula until the last row
Hope it helps!
I'm sure that others will provide a much more elegant solution but this takes the data as presented in the spreadsheet and can be implemented in just a few minutes.
Paste this formula in Cell F3
=FILTER({A3:A13;B3:B6;C3:C5;D3:D5;E3:E5;A18:A21;B18:B20;C18:C20;D18:D20;E18:E19}, LEN({A3:A13;B3:B6;C3:C5;D3:D5;E3:E5;A18:A21;B18:B20;C18:C20;D18:D20;E18:E19}))
This creates a single column list compiled from the various smaller lists.
Highlight the range of names created in Column F (based on the test data = F3:F41), click Copy,
Highlight cell G3, click Paste special (Paste Values only) - this converts the formula to a list for entries.
Paste this formula in Cell H3 - this removes any data in brackets
=left(G3,iferror(search(" (",G3)-1,len(G3)))
Copy the formula down as many rows as there is data in Column G
Paste this formula in cell I3 - this lists the unique names
=unique(H3:H41)
Paste this formula in cell J3 and copy down as many rows as there is data in Column I - this counts the number of instances of each unique name in the master list.
=COUNTIF(H:H, I3)
I've been trying to import some values from a JSON file but they keep adding things to the list and it's a big no-no for me (it has 2,000 rows of items already). I didn't see any information about this, and I don't understand the INDIRECT or ADDRESS functions.
Can anyone explain it a bit?
An example of what I'm doing.
I'm using Google Sheets not Excel and Sheets doesn't like unfinished formulae so when I try to concatenate the formula it adds the end brackets on mid formula!
You have to use a formula if you are attempting to concatenate strings in Excel.
What I do is put everything before the text to be inserted:
import("api.kitchen.utility/
into a cell, say E1, then the following text in E2:
"; "noheader,notruncate")
Assuming the text you want to include is in A1 - A??.
In B1 put the following formula:
=$CONCAT($E$1, $A1, $E$2)
Copy B1 and paste down to rest of range.
$E$1 means the pointer will always point to Cell E1 no matter what. The $A1 means the column will always will be 'A' but the row will increment when it is increased due to copy or fill.
A bare reference G10 (in H10) when pasted or filled always refers the the cell to the immediate right.
In other words add a $ to a row, column, or both to always point to the same row, column or cell.
I've been toying with a few ways to do what I want to do, so I'll start with an example of my goal:
So, in the linked sheet, I have a table with colors and animals, and then a list of entries, each with a color and animal together. My goal is this: Take the string from one of the cells in column E, i.e. E2: Red Cat, and use that information to find the associated cell, and return either the cell reference B2, or the data contained where they intersect, in this case TRUE.
I opted for the cell content rather than the cell addresses. Please try:
=OFFSET($A$1,MATCH(INDEX(split(E2," "),1),A:A,0)-1,MATCH(INDEX(split(E2," "),2),$1:$1,0)-1)
If you alter a little bit code given by #pnuts then you will get cell reference:
=ADDRESS(MATCH(INDEX(SPLIT(E2," "),1),A:A,0),MATCH(INDEX(SPLIT(E2," "),1,2),$1:1,0),4)
The last paramether could be 1-4 and the results:
$B$2
B$2
$B2
B2
also you are able to add sheet name to reference, then it would be:
=ADDRESS(MATCH(INDEX(SPLIT(E2," "),1),A:A,0),MATCH(INDEX(SPLIT(E2," "),1,2),$1:1,0),4,,"SheetName")
and the result -> SheetName!B2
Maybe a good way to automate your task is to use array formulas:
The formula is F1 to split values:
=FILTER(SPLIT(E2:E," "),E2:E<>"")
The formula in H2 to get addresses:
=FILTER(ADDRESS(MATCH(F2:F,A:A,),MATCH(G2:G,1:1,),4),E2:E<>"")
or put this in H2 to get values:
=FILTER(VLOOKUP(F2:F,A:C,MATCH(G2:G,1:1,),0),E2:E<>"")
Tried searching and checking Google documentation but I am still having issues getting the results that I want for this problem.
I'm needing to split several comma-separated lists of items and recombine them so that first items in each list is combined, followed by the second item, etc.
To ask with an illustration, if I have a cell with the following
Paul, John, George, Ringo
and another cell with the following
McCartney, Lennon, Harrison, Starr
How do I use one function to produce this in a cell?
Paul McCartney, John Lennon, George Harrison, Ringo Starr
Here you go, you will need to copy to every row - but assuming your data is in columns A and B it will work across a dynamic number of items:
=ARRAYFORMULA(join(",",split(A1,",")&" "&split(B1,",")))
See image example below, in row one i used the data you showed up top, and in row two i reversed the column data just to show as an example:
If you paste the first word CSV to Sheet1 and the second word CSV to Sheet2 then you could put the following into sheet3
In Cell A1:
=Sheet1!A1&" "&Sheet2!A1
This is saying take the value in sheet1 A1 and then a space " " then the value in sheet2 A1
You could also do this with the concatenate function:
=CONCATENATE(Sheet1!A1," ",Sheet2!A1)
Then just copy the formula to suit.