Google Sheets multiple IF(COUNTIF()) possible in same formula? - google-sheets

I have been googling multiple hours now and still cannot find a solution for a Google Sheets problem.
I have two images, the first image is in the cell A1 and the cellname is called "Image1". The second image is in B1 and the cellname is called "Image2". I have two columns of set names, all names in column1 are related to Image1, all names in column2 are related to Image2.
Column1: K1:K4
Column2: L1:L4
I want the name-related images to be displayed next to the names I write down in another column according to if its a name from column1 (Image1 should be displayed next to it) or a name from column2 (Image2 should be displayed next to it).
D4 = First cell where I start writing down names from column1
G4 = First cell where I start writing down names from coulmn2
If I only write down names from column1 I have no problem to display Image1 next to it. Same with names from column2.
I am using those formulas:
=IF(COUNTIF($K$1:$K$4,D4),Image1,"")
=IF(COUNTIF($L$1:$L$4,G4),Image2,"")
The images are displayed correctly to the related names.
Now, if I write and mix down names from both columns I don't know how to automatically display the correct image related to the name in the cell.
Is it possible to combine =IF(COUNTIF)) multiple times?
GoogleSheetsSample

Yes, you can use them together like this in cell J12 on your test sheet:
=IF(COUNTIF($K$1:$K$4,I12),Image1,IF(COUNTIF($L$1:$L$4,I12),Image2,""))
An arrayformula will save you the trouble of dragging down the formula. Add this to cell J12 and delete all content in J13:J1000:
=arrayformula(IF(COUNTIF(K:K,I12:I),Image1,IF(COUNTIF(L:L,I12:I),Image2,"")))
For the arrayformula to work, the criterion for each countif needs to be from the cell where the formula is located (eg, J12 in this example), to wherever you want the criterion to keep working to. I've deliberately left it to :J so it works to the bottom of the sheet.
The countif ranges don't need to be fixed and they can be the entire columns if you wish K:K and L:L. Or you could set a range if you don't want the countif to go past a certain row (eg. K1:K9 and L1:L9).

Related

Google Sheets - Split Rows From Within One Cell and Drag adjacent Names to Match

I want the title in Cell A1 (Example Title) to be in a row next to each entry in Cell B1 so my desired result is:
In Excel OR Google Sheets. I only see "Split Text To Columns"
There are many ways to go about this. I'll suggest one of them.
Suppose that your raw data is in Sheet1!:A2:B. Add a "Sheet2" and make sure that A:B is empty. Then place the following formula in Sheet2!A1:
=ArrayFormula(QUERY(SPLIT(FLATTEN(SPLIT(REGEXREPLACE(CHAR(10)&Sheet1!B2:B,CHAR(10),"~"&Sheet1!A2:A&"|"),"~",1,1)),"|"),"Select * WHERE Col2 Is Not Null"))
To understand how this works, you need to work from the inside out.
First, an extra line break (CHAR(10)) is added to the start of each cell in B2:B. This is to create a uniform breaking point before every entry in the Column-B cells.
That now-uniform CHAR(10) is replaced by REGEXREPLACE with a concatenation of a tilde (~), the Sheet1!A2:A data for that row and a pipe symbol (|). Thus far, all of the virtually-held data for Sheet1!B2:B will still be within its original cell space.
SPLIT now splits that new data at the tilde to create individual horizontal cells that each now contain a separate copy of the Sheet1!A2:A label, a tilde, and one of the list items from Sheet1!B2:B.
This new virtual horizontal and vertical grid is then FLATTENed into one column.
Again, SPLIT is applied to separate the Sheet1!A2:A label from each of the now-individual Sheet1!B2:B entries, resulting in two columns.
'QUERY` is applied to keep only those results which are not null in the second column (ruling out any results for blank rows in the raw data or errors in column one formed by the previous functions, particularly those caused with the assumption that your number of individual data points in each cell of Sheet1!B2:B will vary).

How can I use arrayformula so I got the cell value that used last time?

I have a table of content on google sheet where word list on column B and image name on column C. On column C image name is not given for every cell. Now I need to use ARRAYFORMULA on Cell D1 where it will give the output (Word name and Image Name) on Column D if Row of Column A is not empty. If you look at the attached screenshot, for some Word there is no image name given on column C. In this case I need the image name that used last time.
For example: On Row 17 for WORD 4 there is no image name given. So, in this case the image name will be Image 2 from cell C12 that used previously for WORD 3. I tried it in many different ways but never able to do it with ARRAYFORMULA. The only solution I am using right now is using formula for every row which is not a good solution. I need to do it with ARRAYFORMULA. I don't want to do it with google script.
➡ Spreadsheet link (Please check Tab 1)
➡ Please check the Screenshot
I have added a sheet ("Erik Help") with the following formula in D1:
=ArrayFormula({"Header";IF(A2:A="",,B2:B&" : "&VLOOKUP(ROW(A2:A),FILTER({ROW(A2:A),C2:C},C2:C<>""),2,TRUE))})
This one array formula creates a header and then fills the entire column with results.
You can change "Header" to whatever you like.
IF(A2:A="",, just leaves D2:D null if nothing is in that row of Col A.
Otherwise, whatever is in B2:B is concatenated with a space-colon-space and then a VLOOKUP of all rows within a FILTERed virtual array that contains only rows and Col-C data where Col C is not blank. Because TRUE is chosen as the final parameter, all rows will "look backward" to the last row where Col C did contain data and return that data as the final piece to be concatenated.
=if(isnumber(SEARCH("WORD",B2,1)),join(" : ",B2, indirect(ARRAYFORMULA(address(IFNA(match(2,1/($C$2:$C2<>"")))+1,COLUMN(C2))))),"")
past this formula in D1 cell and drag it ...

Apply same formula to every cell

I have a sheet with several numbers, which I want to convert to percentage. These are scores imported from a form, where the maximum score is 5.
According to the bellow image, the cell B2, I applied a basic formula =(3/5)*100% to convert three to 60%.
In order to avoid copy and paste the same formula into all cells, is there any formula to find all the cells and apply its value, divide per 5 and multiple per 100%? I thought something similar to Javascript such as (this/5)*100%.
https://docs.google.com/spreadsheets/d/1ZtqJaXy1pHkjk1sywGfSodo0FcOoLlkou79cZBk-jmU/edit?usp=sharing
you could treat it as array and on Sheet2 use:
=ARRAYFORMULA(IF(Sheet1!B2:AA="";;(Sheet1!B2:AA/5)*100%))
demo sheet
I've also looked for a solution to this for some time.
I don't think it's possible as a cell can only hold one value and the moment you try to change that value, it will delete the value.
Your best bet is to create a different table on the same sheet that references the specified values, then copy and paste the results (values only).
Just create a second Sheet, then in cell B2 of Sheet2 use the formula =Sheet1!B2/5*100%.
Then copy the formula to all cells of Sheet2.

How to reference a cell in other sheet which contains a referenced cell not locked to this sheet?

I've searched for hours and couldn't find an answer to the following problem:
I have two sheets, Blue and Red.
I want Blue!A1 to be "exactly" like Red!A1 but I find this problem:
Red!A1 contains "B1+B2", both are Red's cells.
However, when I write Blue!A1 like this: "=Red!A1", the return value is something like "=Red!B1 + Red!B2", and not the "=CurrentSheet!B1 + CurrentSheet!B2"
My problem is that I cannot reference the Blue sheet in the Red one because I want dozens of sheets referencing Red in the same way, so when I change A1 in Red I change all the other sheets' A1 accordingly with their respectives B1s and B2s, not Red's B1 and B2.
I want to have a cell in a sheet which can be referenced by any other cell in any other sheet exactly like it was in the first place.
For instance, if I have a cell which contains =B1+B2 in a sheet, I want to reference it in another sheet in a way that the new =B1+B2 references the current sheet's B1 and B2 cells instead of the former one's.
Can someone help me to solve this problem?
Thank you in advance
Alexandre Trajano
Solution 1
Copy & Paste.
In Google Sheets, copy & paste iterates the formula automatically. If you change sheet, it will change the referenced cells to point to the current sheet; if you change location within the same sheet, it will shift the cell references according to how many columns and rows you shifted.
In contrast, cut & paste will move the formula without iterating the cell references.
Solution 2
If you have a truly large number of sheets you want to create based on a template and don't want to c&p a thousand times, you can use Apps Script.
In particular, you will need
Spreadsheet App to create and access new sheets; and
Functions that manipulate cells here.
You can enter the formula via Apps Script as strings.
For example, say you want cell A1 to have formula B1+C1 in a tab named "Sheet1". You can do the following.
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var tab = sheet.getSheetByName('Sheet1');
sheet.setActiveSheet(tab);
var cell = tab.getRange(1, 1); // The arguments are the row and column indices of A1, respectively.
cell.setValue('=B1+C1');
There are many things you can do here with the basic template. You can generate sheets based on some naming convention. You can generate formula based on the cell position. You can create a script that fills in the formula upon the creation of a tab if its name observes a certain rule. etc etc. And naturally, you can duplicate the formulas from one sheet. You will need getFormula() as opposed to getValue.
Note: you can also call
custom Apps Script function directly in your sheet and write your cells using the output of your custom function. But in your case, using the range functions in Apps Script should be more efficient.

Google Sheets: Formulas over multiple sheets

Is it possible to grab the contents of a cell from one sheet and display them on another?
I have 4 sheets. And I want the cells of the third sheet to display the first column of the second sheet on the second column.
if you want to get range from another sheet just use:
Replace 'Sheet' and 'A2:C8' with title and range you want to refer
={Sheet!A2:C8}
For multiple sheets
Replace ';' with ',' for horizontal view:
={Sheet!A2:C8;Sheet1!A2:C8;Sheet2!A2:C8}
Add the sheetname exclamation point to your cell reference
e.g. sheet!A:1
Then drag from the first cell down to as many rows as you need.
Google Sheets allows reference between sheets. the syntax is pretty simple. consider a single cell: =<sheetname>!A2 for example. From there, you can drag down with the bottom right corner, and your your column will now be a copy of an arbitrary column in , in this case A
These are the annotations for cells in google sheets
Sheetname!A:1 For Relative Cells
Sheetname!$A:1 For Absolute Columns
Sheetname!A:$1 For Absolute Rows
Sheetname!$A:$1 For Absolute Cells
Yes. For specific ranges you can use IMPORTRANGE.
Is it possible to grab the contents of a cell from one sheet and display them on another?
Yes. It's even possible to get entire columns of data.
In sheet 2 A1,
=ARRAYFORMULA('Sheet1'!A:A)
The single quotes ' can be omitted, if the sheet name doesn't have a space . In other words, if you use Monthly Budget as a sheet name, then single quotes is mandatory.

Resources