Locked cell moves when adding rows - google-apps-script

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

Related

How can I add a new row maintaining formatting and formula in Google Sheets

I have a spreadsheet with specific formatting and a running total formula in column F.
Example
The sheet is currently bordered, but when it is full, I want to be able to click the red drawing on the right, and insert a new row above the totals that maintains the formatting and the formula.
I have tried using a macro on both relative and absolute settings but when i do so, it adds a new line in the same spot pushing other lines down and also copies any values in the cash in/out columns for the row above

G Sheets Table of Contents Script

For Google sheet workbooks that have several sheets, I create a Table of Contents sheet that lists all of the sheets in the workbook to increase ease of use for users.
I have looked for an add-on, macro, or script that can speed up the process. No dice. Any ideas for how to automate the process of creating a new sheet that lists the names of all of the other sheets (One sheet name per cell) and then automatically links the cell to that sheet?
Just to expound, this is a great solution except it will not update when you add new tabs or rename/ reorder current tabs. The only solution I could find is to create a simple checkbox trigger.
First I added a checkbox on my Table of Contents tab page. Then I added the script above except, instead of SHEETLIST() in line one I added my checkbox's cell number - for example, SHEETLIST(B3).
Then, I put the formula; in which populates the two columns of data - Name & #GID. In another cell (with plenty of room to list all the tabs) I put the top =ARRAYFORMULA... (not the one with the VLOOKUP) but, again, instead of empty parenthesis after SHEETLIST() I input my checkbox's cell number in both places, like below:
=ARRAYFORMULA(HYPERLINK("#gid="&
QUERY(INDEX(SHEETLIST(B3);;2); "offset 1");
QUERY(INDEX(SHEETLIST(B3);;1); "offset 1")))
I then hid the columns with the NAME & #GID data so you can only see the hyperlinked Table of Contents.
Now, whenever I update my tabs I just click the checkbox and it forces everything to reload. Not completely automatic/ dynamic but the best solution I could find.

Applying formulas on cells in separate Google sheets

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")

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);

Google Docs Spreadsheet form entry add record

I have a Google Docs sheet that is primarily maintained by form. I have several functions that act on this & another sheet within the same spreadsheet. I would like to have one of my functions add a record to the same sheet that the form is typically entered on, but need each of these rows to maintain their position in the sheet.
I have noticed that when I add the record thru the script at the bottom of the sheet & then another record is added thru the form that my script records are moved down to the next row of the spreadsheet. What can I do to prevent this (cause the form to place the next record at the bottom not just underneath the last form entered record)?
I believe you require the "script-added" record to be absorbed into the form responses, which is defined by the light grey area. I provided a workaround here which simply involves copying the last row "in place" after it has been added, which causes it to be absorbed into the light grey area (as long as it is immediately adjacent to it).
So, say you have a variable range that you use to set your values at the end of the script, then use something like this:
range.setValues(values);
range.copyTo(range);