Set the content of a cell to a function? - google-sheets

I have a spreadsheet in which I want to be able to expand the number of columns using a function rather than using auto-fill because the new cells are getting filled with content based on complex formulas and depending on a lot of things.
In one of these cells I want the content to be something like =SUM(A1:A8)
But if I just do cell.setValue("=SUM(A1:A8)") I get "error: Unknown range name A1", unless I afterwards edit the cell content and press enter, without really having changed its content.
Is there any way of fixing this?
I don't want the calculation to be in the expand-columns-function because I do want the cell-calculation to be updated when one of the referenced cells change.
Is there a way of doing it besides having an onEdit-function listening to changes in the referenced cells and updating the calculations?
Thanks

To set a formula on a cell you should use cell.setFormula not setValue.
I'm not sure I understood you "expand" issue completely, but I think an opened range sum function may suit you better than apps-script. e.g.
=SUM(A:A) or =SUM(A2:A)

Related

Making a task list that, when clicking a checkbox, a task fully gets grayed out but having trouble copying the conditional formatting

Essentially just as the title says, I'm making a task list with a "Finished" category that has checkboxes. The way I currently have it set up is that, with the conditional formatting, when you hit the checkbox, the entire row gets grayed out as the task has been completed.
Since it's a big list, however, I don't want to have to go through and do the conditional format rule for each and every row as it descends. I thought I could just do the normal drag down thing but when I try to, it doesn't change to the appropriate cell number in the formula that's in the conditional formatting rule.
I've attached some screenshots of what I'm talking about so, if anyone can help me figure out how to do that, that'd be amazing, thank you!
What the sheet looks like
Conditional Formatting Rule
Set the range to B3:J100 (or whatever range you want the CF to be applied to) and use as a custom formula
=$K3=TRUE
This rule should work for all the rows in the dedicated range.

Change cell value based on checkbox in Google sheets

I'm using Google sheet to manage my budget (see sample below) where I add each of my expenses as a single entry (yes, sounds like a lot of work). I sometimes split the expense with my roommate but then I have to add the value and divide by 2 everytime.
I was thinking if I could use a checkbox next to the value that will automatically divide the expense number by 2 when I check it. Is this possible?
I'm open to simple suggestions other than the checkbox to automatically update the value. Thank you.
Using simple IF formula you can just check if the checkbox is true, if it is then it will divide the current value on column C by 2. Otherwise it will remain blank.
Formula:
=IF(D1,C1/2,"")
Drag down to other cells.
Result:
Suggestion, Alternate solution:
If you'd like you can make a table with a column for your roommate, instead of editing the actual column so you can see both values. And use this formula:
=if(NOT(D2=""),E2/2,E2)
You have a column for per head contribution/split. If the cell on roommate is blank then it will stay as the total value, if roommate has an additional then it will be added to total and split it by 2.
Or using arrayformula:
=arrayformula(if(NOT(D2:D=""),E2:E/2,E2:E))
Works the same as above you just have to fill the enter the formula in the first cell no need to drag down and it will automatically expand to rows/cells below just make sure that below cells are empty or it will return an error.
Additional - Using same cell
As you've mentioned in the comments. Here's a way to divide the original value without using another cell to store it. (Not recommended)
Formula:
=VALUE/IF(D1,2,1)
example:
=1000/IF(D1,2,1)
Result:
However, I do not recommend this. It is still best to make use of another cell to store the original value before making calculations to it.
Also, using this formula you have to change the value from the formula and not on the cell otherwise you will replace the actual formula.
You can try array approach-
=ArrayFormula(IF(D1:D,C1:C/2,C1:C))

Hyperlink to particular Text in a cell on the same sheet

I'm working with Excel 2010. What I'm trying to accomplish is creating a hyperlink which finds a cell containing some specific text, and simply brings the user to that cell. It would be simple if the cell stayed in the same position in the column, but more data is always being added to that column, and the cell location which contains the text keeps changing.
Although I've seen several articles that I suspect might address the problem, they were so involved that I couldn't be certain they were what I was looking for, since I've been away from this for years, and am relearning it all from scratch.
Thanks for your time and attention.
Say we want to go to "treasure" in column D:
=HYPERLINK("#d" & MATCH("treasure",D:D,0),"jump to treasure")
This can be modified if you did not know which column to search!

stop Google Sheets from reformatting/structuring cell formulas

I have some formulas in a Google Sheet cell. If I restructure the formula, like by adding new lines or spaces, for legibility, it undoes my changes. Is there a way to stop this? It seems to only happen if the cell had the formula before. If I put the formula in a new cell it doesn't do that.
This is on Enterprise G-Suite so I cannot share an example sheet.
Blank cell:
Add a structured formula:
Now if I edit the structure it does not retain the changes. In the example below, I removed a new line after TRUE.
Before hitting enter:
After hitting enter:
Also, if I add the same formula to a new/different cell, regardless of how I structure it, it'll restructure to match the one from the other cell.
Google Sheets remembers forming even upon deletion/insertion in new cell. the only way how to achieve what you ask is to introduce a change that directly affects the output calculation. if the output calculation remains the same after the change in structure/formatting then your only possible option is to use lowercase for formula. in other words, if you change your IF to if or If or iF it will register it as new change and therefore the formating will be not reverted to the previous existing state.
the less preferable but working solution would be to wrap it in some useless formula. for example:
=QUERY(IF(TRUE, "hello", "bye"))

How do I make a sheet filter only show checkmarked rows with multiple variables in G-Sheets

I have a spreadsheet in google sheets that has a lot of checkmarks:
I want to create another checkbox filtering system, either at the top, if possible, or on another tab if not. I've tried putting the filter at the top, but as I'm sure you know, it overwrites the data, so no bueno. I also tried this:
with this code:
=FILTER(Movies!A3:P1000,(IF(F2=0,Movies!F4:F1002=0,Movies!F4:F1002=1)))
Which doesn't seem to be doing what I want either? It's showing a random selection, it seems, rather than only the data with the F column being true.
Ideally, you click the checkmarks of the data you want to see, so, if you click the check under Andrew, Addison and Richie, it would only show the rows that had only Andrew, Richie, and Addison's checkmarks. I am fine with making the checkmarks a 0,1,2 list if needed. (Because checkmarks I think are only binary, unless they have an option somewhere to have a third option that I'm unaware of, and marking some data to not be seen if it doesn't have a checkmark would likely require a third option.)
this is what I've got

Resources