Applying formulas on cells in separate Google sheets - google-apps-script

I have two different Google spreadsheets (these are separate files). I would like to calculate the sum of two cells (say A1) in the first and second spreadsheet/file and have it show up in a third/new spreadsheet/file. Is this possible and how might one go about doing this? Thank you.

you can use the IMPORTRANGE formula, which is ("URL of other sheet","range of cells you want to import").
Make sure both parts of the formula have " around them, so that the formula in the 3rd sheet would be something like:
=IMPORTRANGE("Sheet1Key","Sheet1!A1")+IMPORTRANGE("Sheet2Key","Sheet1!A1")

Related

GAS : How to format all empty cells in a sheet

I'd like to format all empty/blank cells in a whole sheet with a white background but I don't find the best method to retrieve a range that can handle all those empty/blank cells.
I don't want to create a conditional rule, I'd like to handle it within a script.
What kind of method should I use ?
Thanks a lot !
P.S : I'm a newbie :)
Read the Sheet Class there's two functions that pertain to rows and columns that can give you the exact number of cells in the sheet with one mathematical operation.

Google Sheets Cell Formatting Conditional on Cell Change (GOOGLEFINANCE)

I am trying to achieve the following: I have a google sheet with a stock price pulled from =GOOGLEFINANCE("ticker", "price"). I want that cell containing the stock price to flash green or red conditional on that cell updating with a higher or lower price as before.
I want to avoid having any form of helper cells, storing old values of the price, etc.
Is this something a script would achieve?
Thanks a lot for your help, everyone!

Locked cell moves when adding rows

I need to protect specific cells within a sheet. For example, I3:I5, J7 and K3:K5. Protecting a cell is easy. The challenge is I need to add new rows to the stop of my spreadsheet each day. When I add these new rows, the protections move by however many rows I add. For example, if I add 10 rows, my protections are now: I13:I15, J17 and K13:K15. How do I avoid these protections moving? I've tried putting in a $ to keep the reference but google sheets strips out dollar signs in protect cells. Is there a simple way to avoid the issue of protected cells moving?
Thank you,
Dave

Intelligently Fill Down Custom Function With Range Parameter in Google Sheets

I have a range of cells that come color coded (background color) from another system (that exports its data into excel format, which I have imported into Google Spreadsheets/Sheets) and I need to make simple calculations based on the background color of each cell.
Unfortunately, the only way I've found in Sheets to determine the background color of a cell is through the use of a script, which I have no experience with.
I have been using the following script:
function getBGColor(range) {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
return sheet.getRange(range).getBackgroundColor();
}
My issue is that the range must be entered in quotes. My understanding is that the value of the cell is passed to the function if the range is entered without quotes. Correct?
=getBGColor("E2")
Sheets doesn't intelligently fill down values in quotes. When I fill down, the formula does not increment as I would need it to (there are hundred of cells I need to get the color of).
I get
=getBGColor("E2")
=getBGColor("E2")
instead of
=getBGColor("E3")
=getBGColor("E4")
I feel like I must be searching using the wrong terminology because I can't find any solutions to this. Do I need to create a custom function that replicates the intelligent fill-down functionality or is there some other solution that I've missed somewhere? Am I attacking the problem incorrectly?
I try to make sheets that I can re-use when new data is available and that can be manipulated on the fly (lots of cell references) to demonstrate the effects of changes in data but it is looking like Sheets may not be the best tool for this? Excel has worked well but my superiors are pushing to move all of this kind of data into Sheets.
Thank you.
Just found something that seems to work. While the
CELL("color",reference)
doesn't work, it did lead me to the address info_type. I was able to use the following workaround:
=getBGColor(CELL("address",E2))
which will intelligently fill down.
If there are better ways to do this please let me know!

Determine the height of merged cells in Google Spreadsheet

I am creating a spreadsheet that will sum the daily inserted hours per activity for each week individually. This spreadsheet allows an increase in height for each week as needed
(ex. week 3 in image below demonstrates another row for inserting a 3rd activity per day).
What I would like to do is find a way to determine the height of the merged cells on the left to be used in dynamically determining the cells to include in a sum total in the last column.
I have found how to determine the existence of merged cells and how to determine the width of merged cells by exporting to HTML, but the latter seems it would not work for my situation as I am looking for a way to do instantaneous height determining to be used in an essentially fancy sum function.
I would like to know if/how it is possible to dynamically determine a merged cell's height using google apps script within google spreadsheet.
Any suggestions or guidance would be appreciated!
I'm assuming that you know where the first row of where the merged cells is. If you know the row position of the merged cell you want to change, I think you can use the getRowHeight() method of the Spreadsheet class, which returns an integer.
getRowHeight Google Documentation
If the problem is, that you can't find the row position of the merged cell you want to change, that's a different question I guess.
You can also set the height:
setRowHeight
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Sets the first row to a height of 200 pixels
sheet.setRowHeight(1, 200);