How do you remove "#REF!" in one sheet linking formula if a cell in another sheet is removed? - google-apps-script

I have the following Google Sheet.
Sample
I have an Apps Script code called onEdit(e). When you enter a date into column B of the Qualifications sheet, the Employee is cut and pasted to into Qualifications - Employees Left sheet. That works perfectly but it creates a #REF! issue in the sheet called FormRanger and which is used to form my dropdown in Google Forms and in the other sheets.
The Employees name needs to remain in the spreadsheet so that it can populate the Qualifications - Employees Left sheet for future reference and in case the employee returns. I, however, want the employee's name (now #REF!) removed from the FormRanger sheet.
Would really appreciate some help with the code.

You want Columns A and B of sheet "FormRanger" to always reflect the active employees.
At present, this is done by assigning values to each cell such as =Qualifications!A5 but when an employee is deleted, this leaves #REF on "FormRanger".
An alternative is to make the values in Columns A and B dynamic by using a QUERY command.
=query(Qualifications!A5:D,"select A, D",0)
To use the formula
delete the entire contents of cells in Columns A and B or "Form Ranger" (1000 rows).
insert the formula in cell A2 of "FormRanger"
The formula will populate both columns A and B, and will also fill down the appropriate number of rows.
When an employee is deleted, the values will automatically adjust.

Related

Can I show the results of COUNTIF in one column only if there is data in another column?

I have a spreadsheet with multiple sheets.
Sheet A is generated from a template, and it is where users will enter in data to be formatted into a report; it will be deleted after that report is submitted.
As people enter info into Column A of Sheet A, they don't have to enter client information if we already have them entered in this spreadsheet, but otherwise they need to go over to Sheet B and enter it in.
To make it easier for them (so they don't have to check every time, or go back and enter info later after getting an error generating the report), I have used conditional formatting. The way it works is, column Z is set up as a helper column, and uses a "COUNTIF" function to check if the client ID in Sheet A, Column A is found in Sheet B, Column C. Sheet A Column Z returns 0 or 1 (or, theoretically, more than one if we had duplicates), and then Sheet A column A has conditional formatting based on Column Z's value-- if the client is already in, the cell for client ID turns green after they type it; if not, it turns red.
It works great! However, I am adding scripts to these sheets, and looping through them. This helper column is filled from Z1 to Z1000, which means I can't use sheet.maxRow() to get the last row.
I see plenty of workarounds on the script side, but I was wondering if anyone has a clever way to input a value into the helper column Z ONLY IF the corresponding cell (same row) in column A has a value using spreadsheet formulas.
I suspect that an array formula with a filter might do it, but I have little experience with either and can't get anything to work out.
Thanks for your help!
You can use this expression with INDEX, MAX and ROW to make an ARRAYFORMULA only expandable until the last cell with value in column:
A2:INDEX(A2:A,MAX(ROW(A2:A)*(A2:A<>"")))
It will go from A2 to the maximum number of row in A in which A is different than null (that's why both conditions are multiplied).
Then you can set a formula like this in Z2 (check the ranges in case something is not right from reading your text, and delete all other formulas in Z too in case you weren't using an arrayformula already):
=BYROW(A2:INDEX(A2:A,MAX(ROW(A2:A)*(A2:A<>""))),LAMBDA(each,IF(each="","",COUNTIF('Sheet B'!C:C,each))))

How to crossmatch data of a column with multiple column and take action if it matched?

Here I have two sheets in google spreadsheet.
Please check the screenshot
I would like to automatically search all the single data of column A of Sheet 2 in Column A and C of Sheet 1 and if it matched it would make the checkboxes ticked on column B and D of sheet 1 and if its not matched it would leave it as it was. I have attached that screenshot which is the result I expect. Is there any functions or script to do this?
I'm not familiar with such staffs. A help would be greatly appreciated.
Thanks
you do not need to write a script for this - an array formula can do it all
to the formula start working - you need to clear out everything from the range B1:B7 . then paste the formula =ArrayFormula(IFNA(VLOOKUP(A1:A7,Sheet2!$A:$A,1,false),)=A1:A7) into cell B1, then select range B1:B7 and paste checkboxes through the menu Insert - Checkbox
the formula for the range D1:D7 is inserted in the same way
=ArrayFormula(IFNA(VLOOKUP(C1:C7,Sheet2!$A:$A,1,false),)=C1:C7)
after some thought, came to the conclusion that the formulas could be much simpler
=ArrayFormula(COUNTIF(Sheet2!$A:$A,A1:A7)>0) for cell B1
=ArrayFormula(COUNTIF(Sheet2!$A:$A,C1:C7)>0) for cell D1

How to import data from a sheet where sheetname is dependent on a cell value

I have been trying to make a Google Sheet for some purpose which shall have details of various movies.
Here is the link: https://docs.google.com/spreadsheets/d/10-4BWaK-zmTxmqr2ov7AvjQW-wAFR8NKXkICuCK1dTY/edit?usp=sharing
Now I wish to count the number of movies per year where sheet name is dependent on cell value.
For example, in Sheet: "Data" I wish that B2 shows the count of movies in Sheet named '2019' but I don't want it to be written as '=COUNTA('2019'!A:A). Instead I wish that the sheet name automatically gets picked up from cell A2. So if I change the year in A2, the Count in B2 should change automatically.
I tried using INDIRECT and MATCH function as =COUNTA(INDIRECT(A2,false)) and =MATCH(A2,INDIRECT(A2),1) but I think I made some errors.
Also in the same way I wish to count in C2 but with a condition: to count only those cells from G column where value is watched
In B2 try
=sumproduct(INDIRECT(A2&"!A3:A")<>"")
and see if that works?

Count the values from a variable column

I have a problem writing down a formula or a script in Google Sheet or Google App Script to find and count the values in a sheet where the number and references to the columns change.
I have a script that copy&paste the Sheet files for the staff shifts of every week from a Drive folder and merge them side by side (in horizontal).
In this sheet that contains all the shifts merged I want to count all the cells of the staff filtered only for handler and picker (column B, K, etc.) according to a specific date (row 3) for every hour.
Example: if today is 28/10/2020 find the right column with the same date in row 3 --> column E, count all the values from row 4 filtered by picker or handler for every hour (10 people at 05 AM).
Do you think that I can implement this with a formula (like a matrix, vlookup, etc.) or should it be written as a Script?
Thank you very much,
Marco
Please use the following
=COUNTA(QUERY({A3:I;J3:R},"select Col"&MATCH(A1,A3:I3)&"
where Col2 matches 'Technician|Picker' "))
Where B1 holds the date you wish to search for (28/10/2010)
Try the below formula. Replace date with your search date.
=COUNTA(INDEX(A4:R14,,MATCH(DATE(2020,10,28),A3:R3)))
This was earlier tagged as excel. This is how to "tackle" this in excel (office 365):
In a clear column use the following formula to get the unique hour-values that are in the column that equal today:
=UNIQUE(FILTER(INDEX(($4:$1048576,,MATCH(TODAY(),$3:$3,0)),INDEX(($4:$1048576,,MATCH(TODAY(),$3:$3,0))<>""))
In the column next to that type the following to get the result of the count of those unique values for that day:
=COUNTIF(INDEX(($4:$1048576,,MATCH(TODAY(),$3:$3,0)), FILTER (I:I,I:I<>""))
Where I:I in FILTER (I:I,I:I<>"") needs to be changed into the column you put the first formula.

I need to run a function when a cell changes value because of formula

Column D in my sheet contains a calculation of values in the row either by average, median, or mode based on user input. I need to run a function that will copy the formula's resulting value to a different spreadsheet each time the cell changes value. I have looked at onEdit() but don't understand it well. I won't be editing the cell directly. I don't want the cell to be copied if any cell in the row changes, only if the calculated value of that particular cell changes. Is this possible? Any help is appreciated greatly.
Column D contains:
=IFERROR(VLOOKUP(BU6,$A$106:$B$110,2,TRUE)," ")
BU6 contains: =IFERROR(ARRAYFORMULA(IF(C6="Average",BR6,IF(C6="Median",BS6,IF(C6="Mode",BT6))))," ")
A106:B110 contains:
When Column D changes from (let's say) A to C, I want to copy that letter into a different spreadsheet.