How can I add a new row maintaining formatting and formula in Google Sheets - google-apps-script

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

Related

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!

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.

Script for copy over values only via button

In this sheet, I have some boxes which calculate information, (Columns K:BO)
I have drawn a button next to each box (ADD LINE)
I need a script attached to the button that will transfer only the information in the coloured cells from each box across to a "Collection Box' in Column (DC:DK)
Each box calculates differently and sometimes I may not need information from all boxes at once hence a button for each one.
The goal is to be able to organise the information so I'm able to copy and paste the information the from the Collection Box (DC:DK) as needed so I don't have to painstakingly extract the information bit by bit
For Example...
I have made a box in Columns CF:CN which only mirrors the information I require.
Problem is when I'm not using certain rows the information gets hard to read because of the cluster,
As you might see I've tried to overcome this with basic cell formatting to highlight the information that I'm using at the time
Also the cells in columns CF:CN has cell references applied so I can change the output in columns as needed.
This would be ideal for me to keep.
I'm not sure on the boundaries of the script, but is there a way that when the information is copied to the collection box so it can still utilize the cell reference to change the information without me having to re-enter?
Here is Sheet
Information is in Update Price Tab
https://docs.google.com/spreadsheets/d/1UdYCqgKEGJeh4KajxQWfTCi-JRpQgGM7435Q_VwHIH8/edit?usp=sharing
a script for copy-over values only is:
function moveValuesOnly() { var ss = SpreadsheetApp.getActiveSpreadsheet();
var source = ss.getRange('Sheet1!A1');
source.copyTo(ss.getRange('Sheet1!B1'), {contentsOnly: true}); }
this particular one will copy values from Sheet1!A1 to Sheet1!B1 if attached to a button

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