Context:
I have a Google Sheets document with my daily tasks in it. Many of my tasks involve me checking to see if changes have been made to other Google Sheets (referenced in my daily task document) in the past day.
Goal:
I want a function which will tell me when one of the referenced Google sheets was last altered.
Here is an example:
https://docs.google.com/spreadsheets/d/1JV-ZvO1P5PPU2Eoi7qSIKaeBWgHkmAA0BLEh8OmLCGI/edit?usp=sharing
I want the function to be in the B column.
This is fairly simple but will take a bit of code. You can go to Tools> Script Editor and create a function like such:
function timestamp() {
return new Date()
}
You can then use that function in an If statement like the following:
IF(A2="","",timestamp(A2))
If the cell is blank the function will return blank, but when the cell is updated it will timestamp the change in that cell.
If you are unfamiliar with Apps Script you can learn how it works here.
Related
sorry if there's something wrong. My english is not that good and I'm not a developer. I use a Google Sheet to organize my money and I have a bank account that updates everyday with a tax that goes 1,00003%.enter image description here
=(E1-D1)*1,00003
The formula is very basic but it works like I need. So, my problem is that this formula needs to update everyday with the new value, at a specific time, without entering in the spreadsheet. I have some experience with Google Script, but I can't figure this out.
I already thought about getting the API of the bank, but they didn't publish it yet.
Example: 1.017,14 will be 1.017,17 tomorrow (04/29), but without the need to enter the spreadsheet.
You need to use a time-driven trigger
That will run your Apps Script function automatically every day at the desired time.
Now the function itself which will run on trigger, should look something like
function myFunction(){
var sheet = SpreadsheetApp.getActive().getSheetByName('PASTE HERE NAME OF SHEET');
var cell = sheet.getRange("A1"); // or any other cell of interest
E1 = sheet.getRange("E1").getValue();
D1 = sheet.getRange("D1").getValue();
cell.setValue((E1-D1)*1,00003);
}
Please note that this is only a sample and I strongly encourage you to get familiar with Apps Script to understand this code and adapt it to your needs.
Context: I need to develop a Google Sheet to manage yearly cost and revenues from the Charity where I volunteer. This file will be updated from volunteers, so I need to develop a structure which they can use with easiness.
My idea:
have a front sheet with a summary from activities and charts
let volunteers duplicate a template event cost and revenue and add their c&r
Result would have as much sheets as many Events and Charity or Fundraising events/campaign.
But, since the number of sheets is unknown till the end of the year, how can I have a summary sheet?
E.G. How can I sum all costs and all rev? Can I query to search in **all existing sheets the cell that follows an exact string (e.g. Total Rev)?**
You can write an Apps Script - a Google Script service based on Javascript
It is relatively simple to learn and use and it will allow you to loop dynamically through all the sheets without knowing in advance how many there will be.
The following sample script iterates through all sheets minus the master sheet of the spreadsheet to which it is bound and sums the values of the cells "A10" (if this is the cell where you have your costs) together. Finally it sets the value of the sum into the cell "A10" fo the master sheet.
function myFunction() {
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheets=ss.getSheets();
var sum=0;
for (var i=0; i<sheets.length; i++){
if(sheets[i].getName()!="Master"){
var value=sheets[i].getRange("A10").getValue();
sum=sum+value;
}
}
ss.getSheetByName("Master").getRange("A10").setValue(sum);
}
If you take some time to get familiar with Apps Script, you will be able to easily adapt the sample above to your needs.
I would recommend that the volunteers don't fill out anything on the sheet at all.
You can collect all you need from the volunteers via a google Form. That form will dump all the data into a single tab in google sheets from which it will be easy to analyze and summarize the data that you want to see and share with the whole team.
I am creating a home budget for myself in Google Sheets, working in Chrome on Windows 10. In the end, the budget will be composed of separate sheets for each month, containing tables for each Friday (payday) within that month. All such tables will follow a certain format and will pull arrays of budget data from an auxiliary sheet.
However, trial-and-error (mostly error) is abundant, and one quails at the thought of having to paste corrections across 52 tables. Is there any way to have each table emulate a formula set down in a template? For example, ideally, my template would contain something like:
=INDEX(IF(condition(relativeCell),namedRange1,namedRange2)
and the final product would pull that formula (with relative reference) to each table. If I discover a mistake or need to make a change, I can simply change the template, and all of the live tables would update their formulas.
Can this be done in Google Sheets?
Failing that, I already have a function that returns a cell's formula as string text. Can this be used to get the desired effect?
there is a formula called INDIRECT which does exactly that:
https://support.google.com/docs/answer/3093377?hl=en
I receive the data on the P/E multiple in Google Sheets via GOOGLEFINANCE in the following manner:
=GOOGLEFINANCE("GOOGL","pe")
How to write script in Google Sheets that would record the P/E values (or better the values of a particular cell) every day as at, say, 21:00?
Use Google Apps Script.
You want to write a function that uses the Spreadsheet API to get the value of a given Range in a given Sheet, and then append that value in a new row on a different sheet.
You also want to set up a time-based trigger to execute that function.
As an example, for a bound script with only one worksheet:
function copyA1toA2onSameSheet() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sheet.getRange("A2").setValue(
sheet.getRange("A1").getValue()
);
}
Note that getActiveSheet will always return the first sheet from a time-based trigger, as there is no UI instance. If you need a different sheet, consider getSheetByName, or using getSheets().
The title sums it up pretty well. I need a cell of my document to reflect the last time any cell in the document updated. "=now()" doesn't work, because now() is evaluated any time the sheet is evaluated - even if there is no change. This means that even the simple act of hitting the browser's reload button causes now() to update its cell - TWICE!
I'd rather not use the onEdit trigger in script, because that would require that I add that script to 1000+ sheets. I already have a way to edit document through the python sheets API, so it would be fairly easy to automatically add the expression wherever I need it.
Volatile spreadsheet functions are not suitable for timestamps, for the reason you stated.
Use a trigger. You don't need to add a script to each sheet. A single stand-alone Google Apps Script can automatically install an "on edit" trigger for multiple spreadsheets, using forSpreadsheet(key) method. Example:
var ids = ['ss_id1', 'ss_id2', ... ]; // array of spreadsheet IDs
for (var i = 0; i < ids.length; i++) {
ScriptApp.newTrigger('timestamp').forSpreadsheet(ids[i]).onEdit().create();
}
function timestamp(e) {
e.source.getActiveSheet().getRange(1, 1).setValue(new Date());
}
Now, whenever one of the listed spreadsheets is edited, the cell A1 of the sheet that was edited in it will have the time of the edit.
This probably won't work for 1000 triggers, because of current limitations of 20 triggers per user per script. Looks like you'll need 50 copies of the stand-alone script, which is a stretch but still manageable.
Another alternative is to run a scheduled Google Apps Script that retrieves "last modified" dates of spreadsheets in the directory (using DriveApp) and edits those in the spreadsheets.
Yet another is to give up. Maybe you don't need a cell to hold information that is already available in spreadsheet interface, "last edited".