I'm running an online booking sheet for my local squash club (dragging them into this century!) and need to find an easy way to automate navigation to the current date when #1 opening the spreadsheet, an #2 switching sheets while the spreadsheet is open. Without the feature, people will have to endlessly scroll through the season to find today's date.
I've run a formula in column A that will place an * on the row that =TODAY() and would appreciate a bit of advice from people with script writing skills as to whether it would be possible to go to that cell on start up, and when we switch between sheets (we run 2 courts, on separate sheets).
As always, help is very much appreciated, and hopefully there is something that can be introduced that can help.
[edit] I suppose the simplest way, looking back at it now, would be the following I just need to learn how to code it:
OnOpen - Set the active sheet as "COURT 1"
Set the active range for the function as A:A
Go to the last modified cell in that range (as it's always going to the be the cell that I want).
The script should then repeat the process for "COURT 2" and then return to "COURT 1".
Copy of the spreadsheet can be found here:
https://docs.google.com/spreadsheets/d/1NBom_qB9AM_LG2lgrGjNRDbxbSGysVj8H6AXqdgKWD8/edit?usp=sharing
Thanks :)
Mark
Some key concepts that might help. I highly advise that you learn how to script so you don't go asking for code each time you want to modify something.
To run a script upon opening the sheet, you can make use of onOpen() trigger. On the same note, you need to be aware of this trigger's Restrictions.
To operate on another sheet within the same SpreadSheet, use setActiveSheet(sheet). When the sheet becomes active, you can now do operations on it. Check the SpreadsheetApp for more docs info.
Related
I have 50 google sheet files for 50 students. They need to key in their answers in their own google sheet file when they are asked to do so. I have a main google sheet to consolidate their data by using IMPORTRANGE formula. This is my formula:
=QUERY({IMPORTRANGE(...);IMPORTRANGE(...);IMPORTRANGE(...);...},"Select * where Col1 is not null")
I will have 50 IMPORTRANGE in the formula. So as expected, the main google sheet is very lag when the 50 students start to key in their answers at the same time. Sometimes, the formula will show #Value when all the students started to answer the questions at their own google sheet file. I need to keep refreshing the main google sheet so that the data will come out, but it will disappear again in a short while then I need to refresh it again (although it will settle down once most of the students finished answering the questions).
I know that using IMPORTRANGE is really not an efficient way to consolidate their answers in main google sheet file but I don't have other better way.
I tried to write a script so that they can send in their data by clicking the button assigned with the script. However, all the students need to go through the authorization process when they run the script for the first time. They don't know how to proceed when they saw the authorization process (not very good in using computer).
May I know is there any ways or tricks that I can use to solve the IMPORTRANGE issue? Or there are some way to write the script where we are not required to go through the authorization process when we run the script for the first time?
Hope to get some advice and help on this as I couldn't find a better way from Google already. Any help will be greatly appreciated!
If I understood correctly what you are looking is that your spreadsheet show in real-time the data being entered simultaneously on 50 different spreadsheets. I'm afraid that Google Sheets is not the right tool for what you are trying to do the way that you are trying to do it. Basically you have two options : change it or use a different tool.
It's not a good idea to have and array of multiple IMPORTRANGE functions that are being edited simultaneously because while the official docs says that IMPORTRANGE functions are updated every 30 minutes when the source and the spreadsheet having formula are opened at the same time the import is done practically immediately and could happen multiple times during the recalculation making causing it to start over an over again.
Replacing the above array by script might help only if you are open to not have the destination spreadsheet updated on real time as scripts are slow.
Replacing the above array by a program that uses the Google Sheets API also might help only if you are open to not have the destination spreadsheet updated on real time as the spreadsheet refresh.
Regarding running a script without requiring authorization that is only possible when using simple triggers and / or removing all the scopes that require authorization to run. Please bear in mind that you might create installable triggers to run other using the authorization of the user who creates them.
Related
Combining multiple spreadsheets in one using IMPORTRANGE
Why do two users sometimes see different values from importrange?
Multiple IMPORTRANGE
Using that many IMPORTRANGE formulas is definitely a bad idea. What I'd suggest you to do:
keep a list of all your student spreadsheet in your main document
write a script that will browse through all of the spreadsheets from that list and copy/paste values into your main document
create a time based trigger that will run the script every X minutes (or hours), depending on how accurate you want the results to be
This is a simple solution, but efficient. Depending on the amount of data and number of students/spreadsheets you may consider other solutions (like writing a cloud function that will do the same as the script) but I think this will work for your use case
to explain the issue briefly, there are certain sheets in the spreadsheet that are supposed to be hidden constantly.Though they have to be opened sometimes to change some data on them. The issue is that there are multiple collaborators on the spreadsheet getting annoyed by people leaving these sheets open and not hiding them again after they're done.
I have a lot of stuff on the sheet automatized through a minutely cycle anyhow so my first approach was to just hide them every cycle if they've been left open. The problem there is that the hideSheet() figuratively slaps the sheet out of your hand even if you're actively viewing it which shouldn't be happening.
I know that there are functions like getActiveSheet() and after some testing I've seen that this function, if you run it for yourself, returns the sheet you're currently viewing (like I myself am viewing).
My idea to overcome the problem that the hideSheet() function also closes the sheet you're currently viewing was to check whether the sheet is currently active for someone on the spreadsheet.The "myself" case obviously works here as I can just check whether I am viewing the sheet as a case for hiding it or not.
Long story short, does anyone have an idea how I can get a list of sheets that are currently being viewed or like being open on other peoples' ends?
Or if that's not possible to answer, does anyone know how I can ensure that the sheets are being rehidden on a regular basis without having the problem that I might just throw someone out of the sheet while he still has it open?
Try the change installable trigger.
An installable change trigger runs when a user modifies the structure of a spreadsheet itself—for example, by adding a new sheet or removing a column.
It might be triggered by showing/hiding a sheet. If so, your script could log when a sheet was shown then do something with that like polling the active sheet when the edits / change the spreadsheet and if the active sheet is not the same, then hide the sheet that was shown.
Reference
https://developers.google.com/apps-script/guides/triggers/installable
I have a spreadsheet with different sheets in Google sheet, 3 users can edit each one a sheet (protections are set, each user can edit only one sheet). They all can execute a google script function that writes what they edited in a summary sheet. I don't want anyone to be abble to edit the summary sheet, so I set myself as the only available editor.
So my problem is to authorize the 3 users, only through the google script function, to write in the summary sheet. I tried to use the following function :
var unprotected = summarySheet.getRange('G3:G10');
protection.setUnprotectedRanges([unprotected]);
but since the users are not allowed to edit the summary sheet, and since the function is run with the active user, so they can't give themselves the right to unprotect a range in the summary sheet... Do you know how to workaround this problem?
Thanks a lot!
I see two script-based choices, one easy and one quite hard, and one sheet-based choice, that is easiest:
Easy:
You run the "summarize" script instead of them or, you set the summarize script run on a trigger out of your account. Then you actually leave protections alone. You could set the summarize script to run on open with error catching if the user doesn't have the necessary authority to unprotect the summary sheet and/or write to the summary sheet.
Hard:
When they run the "summarize" script it calls a published standalone script that has been given the authorization to make the necessary protection changes. I'll be honest, I wouldn't be able to code this but have seen/heard of similar implementations.
Easiest:
Finally, I want to make sure you've considered having the summary sheet itself contain the necessary formulas, parsing, etc. to summarize data from the other sheets without any need of scripts for this aspect of the sheet. The sheet could call custom functions as needed if the parsing or other summarization functionality is beyond built-in functions' capabilities. The sheet could stay fully protected and update itself in real time as users enter data (no need for users to trigger the summary creation, unless spreadsheet settings have auto-recalculate turned off).
Edited to add: put in A1 of Summary sheet something like:
=summarize()
And have that custom function return a 2-dimensional array of the summarized data.
I am looking to solve the following situation.
I have a spreadsheet that is my "builder sheet" within a spreadsheet. It has several complex formulas to create resistance training programs for athletes I work with.
I would like to make it so that I "build" the program in that spreadsheetsheet/workbook. Then "on command" duplicate that finished program into a spreadsheet/workbook of my choice. I would need the duplicated copy to be independent and retain all formats and values from the original and does not refer back to the source. This is so that I can change the "builder sheet" to the next program I need to make and repeat without loosing any previous made programs.
As I am a sport performance coach, this would save me a lot of time if this possible.
I understand simply spreadsheet functions but nothing within script languages to accomplish this.
Thank you in advance
This is problem can be solved without any scripting. There are 3 solutions, choose what is better for you:
duplicate an entire spreadsheet with the "builder sheet"
duplicate only the "builder sheet" to the any other spreadsheet on your Google Drive
duplicate only the "builder sheet" in the same spreadsheet
I could use some help with writing a script in my Google spreadsheet. First off, I am no programmer and a novice at best on writing code or any script.
I want to use this for a lunch list. The back story: I created Google spreadsheets to act as a digital lunch sheet. Each teacher has their own spreadsheet for their homeroom and the totals for the class populate a master lunch sheet for the head cafeteria worker for ordering. The problem is that the old totals are still present from the day before. Ideally, on the start of a new day, the specified fields on the spreadsheet will auto clear. Click here to view an example of the spreadsheet I created.
In my research I found a thread on how to create a script to do this, but as a button to click that will then clear specified ranges Click here to see the original post. The script is as followed:
function clearRange() {
//replace 'Sheet1' with your actual sheet name
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
sheet.getRange('C4:I12').clearContent();}
What I would like for is there to be a script so that everyday (say everyday at midnight) a specific field/ range is cleared out. I do not want columns or rows to delete because I do not want to lose student names or lunch selections.
Please, any help is greatly appreciated. Thanks in advance for your help, especially with a novice like me. I look forward to hearing from anyone!
- Jason
Follow these steps...
01. Go to https://script.google.com and then add a New Script.
ᴬᵈᵈ ⁿᵉʷ ˢᶜʳⁱᵖᵗ
02. Paste this function
function clearRange() {
// replace 'Sheet1' with your actual sheet name
// replace 'dhrhrejYOURSHETIDerhe5j54j5j' with your actual sheet ID
var sheetActive = SpreadsheetApp.openById("dhrhrejYOURSHETIDerhe5j54j5j").getSheetByName("Sheet1");
sheetActive.getRange('A:Y').clearContent();
}
ˢᵖʳᵉᵃᵈˢʰᵉᵉᵗ ᴵᴰ ᴱˣᵃᵐᵖˡᵉ
03. Goto Run & select Run function and then select clearRange.
Once you have run the script, your spreadsheet should be cleared.
Follow these steps if it works correctly...
04. Goto Edit, Select 'All your triggers'
05. In 'All your triggers' popup windows, select clearRange as the Run function.
06. Set the time as you like. (See the example image)
That script should do what you need. You just need to make a couple of modifications.
Where is says 'Sheet1' you would use 'Lunch' which is the name of your sheet in your example.
In the Script Editor, you can add a new trigger to have the script run every night.
In the Script Editor, go to the top menu "Resources » Current Project's Triggers"
Click the link "No triggers set up. Click here to add one now."
Make sure you set these values:
Run » clearRange
Events » Time-driven
Day Timer
Midnight to 1 am
That should run your script every night sometime between Midnight to 1 AM.
If you want an actual menu item that you can click on within the spreadsheet so you can run the script anytime you want, that's a bit more work. Honestly, if that's your primary function ... it's probably just easier to load up the Script Editor from the spreadsheet ("Tools » Script Editor"), and just select the clearRange function and press the play button.
If you do really want to add menu items, there's additional documentation here » https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet#addMenu(String,Object). Once you've coded the new menu function, you'll have to update your triggers just like you did to run every night. But instead, you'll change the event type to From Spreadsheet and set the value to On open. That way it'll create the new menu items when the Spreadsheet is opened.