Google Sheets: Copy With Protections

  Рет қаралды 23,767

Spencer Farris

Spencer Farris

Күн бұрын

Пікірлер: 190
@johngraham2250
@johngraham2250 2 жыл бұрын
This is brilliant! Can't believe not everybody uses this in their spreadsheets.
@SpencerFarris
@SpencerFarris 2 жыл бұрын
Glad it's helped!
@streetlight7444
@streetlight7444 2 жыл бұрын
hi. i'd copied your script but there's an error occur. here's what it says. 8:07:16 AM Error TypeError: Cannot read property 'getProtections' of null copyWithProtections @ Copy of Code.gs:4 how can I possibly use your script in 2022 update?
@MrNovicto
@MrNovicto Жыл бұрын
Wow, it finally works, hahaha. After trying many times (first time using a script). What I didn't know was after changing the CopyWithProtections file name with my file name and running the script I needed to go back to my original sheet and click the "App Script" in the Extension tab. I can now duplicate my tabs for each month with my ranges still protected and people who make their own copy of my file still have protected ranges in them. Thanks for the script @SpencerFarris ! You've saved me tons of time!
@SpencerFarris
@SpencerFarris 23 күн бұрын
SO GLAD
@kmac33PS5
@kmac33PS5 2 жыл бұрын
Flies to script like we know exactly where to find it. I appreciate the vid, well done!
@SpencerFarris
@SpencerFarris 2 жыл бұрын
My later videos do show the menu to get there, but I was very new to making these when I did this one. Glad you enjoyed.
@juliajones5948
@juliajones5948 4 ай бұрын
THANK YOU!!!!!!!! This is exactly what I needed. What if you want to duplicate a whole notebook with protections?
@SpencerFarris
@SpencerFarris 23 күн бұрын
I just made a new video about making a copy of SHEET protections. Is that what you needed?
@GorillaVape-ui4nd
@GorillaVape-ui4nd 5 ай бұрын
Hello. Excellente video. Unfortunately, the new sheet generated does not copy the protections. In my case, the original sheet is protected but I set exceptions in some cells. Would it be the cause of the script not to run properly?
@SpencerFarris
@SpencerFarris 4 ай бұрын
Yes, that's exactly why. This script is written with range protections in mind and sheet protections work completely differently. I honestly need to just make a new video about that
@aleshamunson1290
@aleshamunson1290 Жыл бұрын
Hi Spencer! You and I were chatting on Google Doc Editor Community, but my question was flagged and profile disabled for some reason. I hope you can still help me! This is what I responded: I want a user to be able to duplicate the "Monthly Budget" tab at their leisure for numerous months. I would like the tab they duplicate (whether it be the original "monthly budget" tab or not) to bring everything over: formulas, format, and cell protection. Also, they will probably rename the sheets as they go (not sure if that's relevant to the script). The protection in place is "can edit: with warnings". Right now, I am using the script from this video, but when I duplicate a tab manually, it doesn't bring over the protections. I can only create exact duplicates if I run the script multiple times. But I would like the user to be able to duplicate a tab at will and get everything over (like excel). Not sure if this is possible. Thanks again for your help! (-:
@SpencerFarris
@SpencerFarris Жыл бұрын
It is only possible to duplicate the cell protections if the duplicate tab is made with the script
@aleshamunson1290
@aleshamunson1290 Жыл бұрын
Ok, thank you so much for responding!! That helps a lot. @@SpencerFarris
@SpencerFarris
@SpencerFarris Жыл бұрын
@@aleshamunson1290 Good luck! And I have no idea why your post was flagged, that's really really weird
@thebeautyfood
@thebeautyfood Жыл бұрын
Hello, Sir! Your video is really helpful. I need to copy a sheet with sheet protection except certain range instead. I've tried to change the "p = nSheet.getRange" but in the end i got some errors. What should i do to make the script run? I need your help. Thanks in advance.
@MrScoredance
@MrScoredance 7 ай бұрын
Do you make it? Need help here
@ArsenalTirePerformanceTech
@ArsenalTirePerformanceTech Ай бұрын
I need this function too Did you make it work?
@SpencerFarris
@SpencerFarris 23 күн бұрын
Sorry it's been SO LONG. I just put out a new video with SHEET protections
@mosntergirlygal
@mosntergirlygal 2 жыл бұрын
Okay Spencer. I am sure someone asked this below, or this video answers it (HA!) - but this is all very new to me and I don't really know what I am doing. What I have is a single google sheet with about 11 titled tabs at the bottom. I successfully was able to share the entire google sheet with 11 tabs, and keep the protected ranges throughout all of them simply by making a copy. Both on Computer and Mobile. Yay, check! Yet, when I make a copy after UNchecking off the boxes of 1. Editors can change permissions and share and 2. Viewers and commenters can see the option to download, print, and copy in the share settings - it resets itself. I know there's got to be a solution out there, because I can't always copy from my phone right away for a client and make these settings mobily. Unless I am missing a step? First, what exactly does Editors changing permissions even mean? I understand the sharing portion, but as for the changing permission - does this mean the same 2 check box items listed above? Second, Is there ANY way to ever share a file where NO ONE except me (owner) can print, make a copy and download? I hate that I am only given the option to not allow "viewers" or "commenters" to have this access when I still need people to make edits, but I don't want them making copies, printing or downloading! I hope that makes sense! I appreciate your help in posting this videos!!!
@SpencerFarris
@SpencerFarris 2 жыл бұрын
The first means that Editors can change if it's shared with individuals or with anyone with the link. You cannot restrict Editors from really doing anything with a file. There is a push for Google to adjust that, but right now an Editor is always able to download/print/copy/whatever
@mosntergirlygal
@mosntergirlygal 2 жыл бұрын
@@SpencerFarris thank you for the reply!!! I really wish they offered that!!
@mosntergirlygal
@mosntergirlygal 2 жыл бұрын
And what would be your suggestion for carrying over the permissions?
@vickyappu1675
@vickyappu1675 2 жыл бұрын
Hey! When I duplicate sheet using script specific editors lose privelage to edit on ranges and only I can do. How to fix this ! Eg : column b1 me and say " Jay " can edit. Column b3 me and say " max " can edit. But when I make a duplicate only I can edit they cannot. I have to share range manually.
@SpencerFarris
@SpencerFarris 2 жыл бұрын
Can you add me as an editor and we can work through it?
@BryanSise
@BryanSise 6 ай бұрын
@spencer thank you for this excellent walk-through and script! I have it working in my Google Sheets workbook. It's all working fine, but the script executes *really* slowly. It literally takes 4-5 minutes to copy one sheet (tab) with protections. (The sheet being copied has some fairly complex formulas and a lot of individual cell protections, but still...) Do you have any tips on how I could speed up the script execution time? Thanks so much.
@SpencerFarris
@SpencerFarris 6 ай бұрын
All that has to do with your computer and Internet, and the difficult of copying the sheet itself. Oftne there isn't a way to speed it up
@DerekSterenberg-i5q
@DerekSterenberg-i5q 11 ай бұрын
How would I edit this code to include both RANGE and SHEET permissions?
@avinashbiju5329
@avinashbiju5329 5 ай бұрын
function copyWithProtections() { // Get the active spreadsheet and the template sheet const spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); const templateSheet = spreadsheet.getSheetByName("Template"); // Copy the template sheet and set a new name const newSheet = templateSheet.copyTo(spreadsheet); newSheet.setName("Copied Sheet " + (spreadsheet.getNumSheets() - 1)); // Adjust this to set the desired name // Get the protections of the template sheet const protections = templateSheet.getProtections(SpreadsheetApp.ProtectionType.RANGE); // Loop through the protections and apply them to the new sheet protections.forEach(protection => { const rangeNotation = protection.getRange().getA1Notation(); const newProtection = newSheet.getRange(rangeNotation).protect(); // Remove existing editors and apply original protection settings newProtection.removeEditors(newProtection.getEditors()); if (protection.canDomainEdit()) { newProtection.setDomainEdit(true); } else { newProtection.setDomainEdit(false); } // Copy the description newProtection.setDescription(protection.getDescription()); // Copy the user and group editors const editors = protection.getEditors(); if (editors.length > 0) { newProtection.addEditors(editors); } }); // Get and apply sheet protection if exists const sheetProtection = templateSheet.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0]; if (sheetProtection) { const newSheetProtection = newSheet.protect(); newSheetProtection.removeEditors(newSheetProtection.getEditors()); if (sheetProtection.canDomainEdit()) { newSheetProtection.setDomainEdit(true); } else { newSheetProtection.setDomainEdit(false); } newSheetProtection.setDescription(sheetProtection.getDescription()); const sheetEditors = sheetProtection.getEditors(); if (sheetEditors.length > 0) { newSheetProtection.addEditors(sheetEditors); } } }
@SpencerFarris
@SpencerFarris 23 күн бұрын
Sorry it's been SO LONG. I just made a new video showing how to do SHEET permissions. It's different
@K1LLA_KING_KONG
@K1LLA_KING_KONG 5 ай бұрын
I used your copy sheet, however I prefer to protect the SHEET and add exceptions. How do I modify this script for SHEET?
@SpencerFarris
@SpencerFarris 4 ай бұрын
I honestly need to make another video with that
@mariafound7377
@mariafound7377 2 жыл бұрын
Spencer, I have a template with protections where faculty will be making a COPY of the template. How do I keep the protections in a duplicated google sheet from a template?
@SpencerFarris
@SpencerFarris 2 жыл бұрын
Is the shown method not working for you?
@mariafound7377
@mariafound7377 2 жыл бұрын
@@SpencerFarris Ah, so your instructions will work for forced copies of a template... ok
@yvettefraga9809
@yvettefraga9809 2 жыл бұрын
Thank you so much! You just save me and my team a ton of time!
@SpencerFarris
@SpencerFarris 23 күн бұрын
Hooray! :D
@jayhive4884
@jayhive4884 Жыл бұрын
Hi, Spencer. I can see your Persistence, thanks for helping people over the comment section. Why don't you drop your Venmo in your video description just so when people want to tip you for your efforts. I also do have a question. Why can't I access Google Script? Like when I go to extensions and choose Script, it just won't load???
@SpencerFarris
@SpencerFarris Жыл бұрын
Do you get an error message, or just forever loading?
@sksungaipetanikpm-sk-admin5889
@sksungaipetanikpm-sk-admin5889 2 жыл бұрын
thanks Spencer, great one. Really helpful. Do you have apps script to copy sheet into another speadsheet with protection?
@SpencerFarris
@SpencerFarris 2 жыл бұрын
What exactly do you mean?
@givemeapps123
@givemeapps123 Жыл бұрын
When I try to Run it, I get "Exception: Range not found"?? It does copy the Sheet but does not copy the permissions. Can it also be modified that rather than it naming it as "1", it will go up in months instead? So if I copy January, it calls it February, and then March, etc.
@givemeapps123
@givemeapps123 Жыл бұрын
Nevermind, I don't think this will work for me. There are updates on a monthly basis. So when I get to October, I will likely want to copy September rather than the original January one each and every time. So with this code, it won't work will it?
@SpencerFarris
@SpencerFarris Жыл бұрын
@@givemeapps123 It should still work fine. Your error above is because ON EDIT FUNCTIONS SHOULD NOT BE RUN MANUALLY
@TenzingDavidSherpa
@TenzingDavidSherpa Жыл бұрын
Hi Spencer, Thanks for the video. I literally just copy pasted your script above (making sure my sheet was named "Template" as well) and it worked for me. The only issue I now have is that it created the copy at the end (complete right side) of all the sheet tabs and it takes me ages to manually pull each individual sheet back to the left. I have a sheet for each day of the year (= 365 sheets) in my file. Is there any way I can create the copy and have it positioned on the left end of the tabs? Thanks again
@SpencerFarris
@SpencerFarris Жыл бұрын
Use SpreadsheetApp.getActiveSpreadsheet().moveActiveSheet(2); to move that sheet to the second position.
@TenzingDavidSherpa
@TenzingDavidSherpa Жыл бұрын
@@SpencerFarris Thank you. It worked when I executed it as a separate function. Is there any way I can incorporate this line into the script you provided above in this video ("copy with protections") so it can be done in one execution rather than having to do the move once the copy has been created? Apologies for the inconvenience. I am new to script. Thanks again
@SpencerFarris
@SpencerFarris Жыл бұрын
@@TenzingDavidSherpa nSheet.getActiveSpreadsheet().moveActiveSheet(2);
@TenzingDavidSherpa
@TenzingDavidSherpa Жыл бұрын
@@SpencerFarris Hi Spencer, Thanks for the persistent effort to help me. I'm still not able to get it to work in one execution. This is what I've done. Could you let me know where I have gone wrong: SCRIPT: function copyWithProtections(){ const sh = SpreadsheetApp.getActiveSpreadsheet(); const ss = sh.getSheetByName("Template"); const prot = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE) let nSheet = ss.copyTo(sh).setName(sh.getNumSheets()-1); let p; for (let i in prot){ p = nSheet.getRange(prot[i].getRange().getA1Notation()).protect(); p.removeEditors(p.getEditors()); if (p.canDomainEdit()) { p.setDomainEdit(false); } } } function myFunction() { nSheet.getActiveSpreadsheet().moveActiveSheet(2); }
@SpencerFarris
@SpencerFarris Жыл бұрын
​@@TenzingDavidSherpa Put that moveActiveSheet() call inside the other function, not as a separate. If you are still having issues please add me as an editor on the sheet
@setyawana.5519
@setyawana.5519 6 ай бұрын
TypeError: Cannot read properties of null (reading 'getSheetByName') why??
@SpencerFarris
@SpencerFarris 6 ай бұрын
Hm, not sure. Can you post your code here and I'll look.
@VIJAYAMIRTHARAJPROMINANCE
@VIJAYAMIRTHARAJPROMINANCE 5 ай бұрын
Great Information...Thanks But, Who is Using this Script (triggering the Script), They Can also Edit the Protected Cells. Is there any way to Edit only by Sheet Owners Not by the Triggerers?? @spencer Awaiting for your Reply
@SpencerFarris
@SpencerFarris 4 ай бұрын
Yes, you need to use an Installed Trigger instead so that you can make it run as the sheet owners
@century21edge
@century21edge 3 жыл бұрын
Hi Spencer... I have a Google Worksheet with several tabs for our agents to track their daily productivity. I've created a "master" template spreadsheet that I need to duplicate while keeping the protections on all the various sheets/tabs within the worksheet. Your script illustrated here is great for duplicating one sheet/tab within a spreadsheet, however, do you know how I can make a copy of the while file while keeping the protections?
@SpencerFarris
@SpencerFarris 3 жыл бұрын
So I would have it loop through all the tabs of the copy, get the protections from the analogous tab of the original, and apply those protections to the copied tab.
@MrScoredance
@MrScoredance 7 ай бұрын
Hi Spencer. Can you help me? How to protect SHEET instead RANGE?
@MrScoredance
@MrScoredance 7 ай бұрын
I use this. But not working. It just copy from template only but not protecting it function copyWithProtections(){ const sh = SpreadsheetApp.getActiveSpreadsheet(); const ss = sh.getSheetByName("Template"); const prot = ss.getProtections(SpreadsheetApp.ProtectionType.SHEET); let nSheet = ss.copyTo(sh).setName(sh.getNumSheets()-1); let nProt = nSheet.protect(); nProt.setUnprotectedRanges }
@SpencerFarris
@SpencerFarris 7 ай бұрын
The code for protecting a sheet does work a bit differently. What have you tried?
@MrScoredance
@MrScoredance 7 ай бұрын
@@SpencerFarris function copyWithProtections(){ const sh = SpreadsheetApp.getActiveSpreadsheet(); const ss = sh.getSheetByName("Template"); const prot = ss.getProtections(SpreadsheetApp.ProtectionType.SHEET); let nSheet = ss.copyTo(sh).setName(sh.getNumSheets()-1); let nProt = nSheet.protect(); p = nSheet.getRange; nProt.setprotectedRanges }
@JosephSalonga
@JosephSalonga 5 ай бұрын
i cannot press the run button what do you think is the problem?
@SpencerFarris
@SpencerFarris 5 ай бұрын
Best guess is it didn't save
@theewealththerapist
@theewealththerapist Жыл бұрын
I am sooo confused but this is exactly what I need for one of my documents. Do I copy the entire code verbatim? Where do I paste the code to??
@SpencerFarris
@SpencerFarris Жыл бұрын
Extensions > Apps Script Delete what's there, paste this
@theewealththerapist
@theewealththerapist Жыл бұрын
Thank you! I see this works when duplicating a sheet within the same document. Is there something to protect various protected sheets/ranges in a document when someone makes a copy of the entire document? Like if I was selling a document to someone and they needed their own individual copy of an entire document?@@SpencerFarris
@SpencerFarris
@SpencerFarris Жыл бұрын
​@@theewealththerapistIf someone makes a copy of a document THEY are they owner, not you, so protections wouldn't do anything there.
@kristellekaygloria5728
@kristellekaygloria5728 2 жыл бұрын
How to restrict someone from making a copy of my entire spreadsheet in google sheets? Thanks.
@SpencerFarris
@SpencerFarris 2 жыл бұрын
Give them view access and toggle "Viewers cannot make copies." Editors cannot be prevented from making a copy.
@elbegzayaoyungerel1523
@elbegzayaoyungerel1523 2 жыл бұрын
Thanks for the helpful video. I'm getting "TypeError: Cannot read property 'getSheetByName' of null" error although i typed my sheet name... Please help😊
@SpencerFarris
@SpencerFarris 2 жыл бұрын
Don't run the script, it runs automatically whenever an edit occurs.
@Cryostatic
@Cryostatic 2 жыл бұрын
@@SpencerFarris I'm getting the same error if I click run and I don't understand your reply. You click run in the video and if I just manually duplicate the sheet it doesn't change as the script is set to do so I'm not sure how to make it cooperate. X3 I've not used Google's scripts before so this is a new task for me.
@Cryostatic
@Cryostatic 2 жыл бұрын
I half figured it out, just isn't holding protection settings for Sheet instead of Ranges. Had to go under the sheet, go to extensions, then apps script. I put the code there and ran it which now duplicated the template but does not carry protection settings unless I change the script back to Ranges and manually specify where can't be edited. Doing a Sheet and specifying where it could be edited was much cleaner but I'm not familiar enough with Google scripts to know the commands to make it work. This method does require me to click run though so I'm not sure if you're expecting it to be done a different way?
@Cryostatic
@Cryostatic 2 жыл бұрын
Error code in case anyone is interested when trying to run it with SHEET in place of RANGE on line 4 :) Exception: Range not found at copyWithProtections(Code:10:16)
@SpencerFarris
@SpencerFarris 2 жыл бұрын
​@@Cryostatic Right, there is some other changes to make it actually work for SHEET protections. I apologize for the misinformation in my first comment. The wording from Elgebzaya made it sound like that was the problem and I was too lazy to check the code at the time :p
@schnurskie
@schnurskie Жыл бұрын
Excellent video. The only issue I am having is an error of "Exception: Range not found" for line 10 of the code. I am copying the protection of an entire sheet with 10 exempt ranges so I changed that line of code to reflect sheet not range. Everything else is exactly the same. I was looking for a solution in other comments with similar issue and saw you mention "ON EDIT FUNCTIONS SHOULD NOT BE RUN MANUALLY" but I have no clue what that means. Think you could help me out?
@SpencerFarris
@SpencerFarris Жыл бұрын
On Edit functions run automatically whenever an edit is made.
@SpencerFarris
@SpencerFarris Жыл бұрын
But you actually have a different issue. SHEET protections are stored differently than RANGE protections. You need to call SpreadsheetApp.ProtectionType.SHEET. I *think* it should work like this: function copyWithProtections(){ const sh = SpreadsheetApp.getActiveSpreadsheet(); const ss = sh.getSheetByName("Template"); const prot = ss.getProtections(SpreadsheetApp.ProtectionType.SHEET).getUnprotectedRanges(); let nSheet = ss.copyTo(sh).setName(sh.getNumSheets()-1); let nProt = nSheet.protect(); nProt.setUnprotectedRanges(unprotected) }
@schnurskie
@schnurskie Жыл бұрын
@@SpencerFarris Thank you very much for the reply. I was able to get what I needed for the short term redoing my format using several ranges protections but it would be a whole lot cleaner if I could get this to work getting the unprotected ranges. I got the following error using the code you suggested. "TypeError: ss.getProtections(...).getUnprotectedRanges is not a function copyWithProtections @ SheetCopy.gs:4"
@ArsenalTirePerformanceTech
@ArsenalTirePerformanceTech Ай бұрын
@@SpencerFarris I loved your video!!! I am not familiar with these codes. Can you put the complete code so I can protect a protected sheet that has several editable field ranges?
@SpencerFarris
@SpencerFarris Ай бұрын
@@ArsenalTirePerformanceTech The script is in the description
@TheCraftyBrick
@TheCraftyBrick Жыл бұрын
thank you for this. I'm wondering if this will be the fix I need for my sheet. I have a sheet (a template per say) I want people to be able to copy and keep on their computer. I want them to be able to edit some cells but not all of them. So far whenever I share it with them even when I change the share link and add "copy" or "template/preview" they are still able to edit the locked cells. Will changing the scrip allow me share a copy of my file with them that they can edit but still not be able to edit locked cells?
@SpencerFarris
@SpencerFarris Жыл бұрын
The owner of a sheet can *never* be forbidden from editing a range. If you want your users to have a personalized copy with protections then you need to make the copy for them so that your account is the owner. Also, G Sheets aren't stored on an individuals computer. They are all cloud-based.
@TheCraftyBrick
@TheCraftyBrick Жыл бұрын
@@SpencerFarris ahhh ok. So if I'm giving the sheet to multiple people and I want each of them to be able to edit but still have locked cells I would need to make a different copy for each person and then share it with them individually. Is that correct?
@SpencerFarris
@SpencerFarris Жыл бұрын
@@TheCraftyBrick Yes :)
@rajeshat9353
@rajeshat9353 2 жыл бұрын
@spencer, is it possible to protect selected sheets, same range in a google sheet file
@SpencerFarris
@SpencerFarris 2 жыл бұрын
Yes, though I don't have that written up at present
@Jumisco
@Jumisco Жыл бұрын
how to copy protection sheet wit exeption some range?
@SpencerFarris
@SpencerFarris Жыл бұрын
What?
@camillehenry7484
@camillehenry7484 2 жыл бұрын
Great video!! Helped me out tremendously. However, how do I keep custom permission for the ranges the same? For example, I have set a range so that only owner and 1 other user (user1) can edit and I have set another range so that owner and a different user (user2) can edit. How do I keep those custom permissions the same?
@SpencerFarris
@SpencerFarris 2 жыл бұрын
You should be able to call protection.getEditors() from the first range/protection and use that in the second.
@camillehenry7484
@camillehenry7484 2 жыл бұрын
@@SpencerFarris Thanks for the speedy reply. However, I don't know anythig about scripting. Where exactly do I put protection.getEditors().
@SpencerFarris
@SpencerFarris 2 жыл бұрын
@@camillehenry7484 If you want me to write it for you, please share the sheet with me spencer.farris@gmail.com and show exactly what you want done
@camillehenry7484
@camillehenry7484 2 жыл бұрын
@@SpencerFarris Thanks. Appreciated.
@elpisadmin5354
@elpisadmin5354 2 жыл бұрын
Hi @Spencer! This really saved me from a lot of things, so thank you. I've got it working. Got a question though, what should I do if I want to apply these to multiple sheets? Thanks!
@SpencerFarris
@SpencerFarris 2 жыл бұрын
Instead of just the Template sheet? Create an array with the desired sheet names and loop through them.
@md.nazmulhossain8690
@md.nazmulhossain8690 6 ай бұрын
Dear, I share my file with another coworker. He wants to duplicate this file. How does he do this?
@SpencerFarris
@SpencerFarris 23 күн бұрын
Are you still having issues?
@ellasmk5841
@ellasmk5841 3 жыл бұрын
You save my life, thank you for scripts.. but, i have a question, how do we keep editor on the next sheet after duplication is complete ?..
@SpencerFarris
@SpencerFarris 3 жыл бұрын
What do you mean?
@thejordanchronicles3769
@thejordanchronicles3769 Жыл бұрын
I am having issues and I am pretty sure it is user error lol. Do you have services or package in which you can assist with setting up protections on a series of google sheets?
@SpencerFarris
@SpencerFarris Жыл бұрын
Let's talk about it. spencer.farris@gmail.com
@ryanpeterson7998
@ryanpeterson7998 4 жыл бұрын
does this also work when you copy the entire document and rename? 2020-12-09 copied to new document 2020-12-10?
@SpencerFarris
@SpencerFarris 4 жыл бұрын
It should, yes.
@Fr3onYTB
@Fr3onYTB 2 жыл бұрын
Hey Spencer Thank you for your video and help
@SpencerFarris
@SpencerFarris 23 күн бұрын
Glad it worked
@20100685
@20100685 3 жыл бұрын
Thanks for the helpful video. What if instead of range protection I want to call sheet protection? I'm getting an "range not found" error. I tried to change the "p = nSheet.getRange" to sheet protection but that just yielded another error. Any additional guidance would be great!
@SpencerFarris
@SpencerFarris 3 жыл бұрын
So you're copying a sheet that is protected? Are you one of the users with permissions on the sheet?
@20100685
@20100685 3 жыл бұрын
@@SpencerFarris yes, I own the whole workbook.
@SpencerFarris
@SpencerFarris 3 жыл бұрын
@@20100685 Can you add me to it? spencer.farris@gmail.com
@TrickyTimeTree
@TrickyTimeTree 3 жыл бұрын
@@SpencerFarris Oh, that's funny, I was just looking at how to copy both range and sheet protection, and I see these comments were just from these past couple of days.
@TrickyTimeTree
@TrickyTimeTree 3 жыл бұрын
@@SpencerFarris Why does it not copy the name of the protected regions over to the new sheet?
@iraklimaxarashvili5803
@iraklimaxarashvili5803 2 жыл бұрын
hello . i have protecteted sheet not range , and i have 18 excepted cells in it. i want to dublicate this sheet ! please help me as soo as u can
@SpencerFarris
@SpencerFarris 2 жыл бұрын
So you want to duplicate that sheet and retain the protection + excepted cells?
@dt5911
@dt5911 2 жыл бұрын
@@SpencerFarris Hi Spencer, great video, instructions and explanation - I have just subscribed to your channel. I have been trying to solve this issue for the past 24 hours, however I have 153 ranges in exception on a protected sheet, and need to create 10+ sheets, working off a tracking point mouse is too fatiguing. If you could help with this I would be grateful. Thanks, DT
@tusharagarwal2657
@tusharagarwal2657 Жыл бұрын
@@SpencerFarrisyes, yes, can you please suggest that -- I am not able to get that to work
@SpencerFarris
@SpencerFarris Жыл бұрын
@@tusharagarwal2657 Sorry, suggest what?
@QuynhTranNhat-o7l
@QuynhTranNhat-o7l 27 күн бұрын
Hi, can we use this for duplicate sheet ?
@SpencerFarris
@SpencerFarris 27 күн бұрын
The protections only copy if you use the script to copy the sheet; using the File > Duplicate option doesn't run the script
@amirrostam318
@amirrostam318 2 жыл бұрын
Hello sir , thanks for this big help, saved a lots of my time . however i have a problem. when the script is finish and i have the copy, its only me that i have the permession to edit, is there any way that script copy the exact editors? cause i have like 20 ppl using the sheet and i want only 5 of them have the access.
@klabrenz
@klabrenz Жыл бұрын
same issue - did you ever find a solution?
@SpencerFarris
@SpencerFarris 23 күн бұрын
Sorry it's been SO LONG. Do you still need help?
@tiger131071
@tiger131071 3 жыл бұрын
Firstly, thank you, this has saved me a bunch of time! However, on my original sheet, I have the protection set to 'show a warning when editing this range'. But when running the script, the new sheet has protection set to 'restrict who can edit this range' instead of 'show a warning when editing this range'. How can I correct this?
@SpencerFarris
@SpencerFarris 3 жыл бұрын
There's a isWarningOnly parameter that can be set. So I think (haven't tested) it should be: function copyWithProtections(){ const sh = SpreadsheetApp.getActiveSpreadsheet(); const ss = sh.getSheetByName("Template"); const prot = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE) let nSheet = ss.copyTo(sh).setName(sh.getNumSheets()-1); let p; for (let i in prot){ p = nSheet.getRange(prot[i].getRange().getA1Notation()).protect().setWarningOnly(true); } }
@tiger131071
@tiger131071 3 жыл бұрын
@@SpencerFarris with a bit of investigation and your help I have got it to work...thank you so much, saved a lot of time!!!
@tiger131071
@tiger131071 3 жыл бұрын
@@SpencerFarris Also, liked and subscribed :-)
@arul255
@arul255 2 жыл бұрын
Hi @Spencer, thank you for the great idea. I have a protected Sheet that I shared with my editors to edit in the selected cell range only, and I am duplicating the same sheet every month. Now I tried to use this script to protect the sheet, But I could not get it to work for me. Please help me if you can. That would be great.!
@SpencerFarris
@SpencerFarris 2 жыл бұрын
Please share the sheet with me. spencer.farris@gmail.com
@klabrenz
@klabrenz Жыл бұрын
hi - this is great, but I need a tweak and wondered if you could assist? I have a spreadsheet that has multiple tabs, one of which is a template tab. I need my team, who have shared access to the spreadsheet, to be able to copy the template tab, including all the permissions on the template tab. I am a newbie when it comes to scripts, but what I noticed with the one you posted here is that the team would have to go to the scripts section and click 'run' in order to duplicate a tab, not feasible since scrips are more of an expert level function. Any help would be awesome! We use our spreadsheet to manage our adoptable cat population - PURRS
@SpencerFarris
@SpencerFarris 23 күн бұрын
Sorry it's been SO LONG. Do you and the kitties still need help?
@vishnutiwari7902
@vishnutiwari7902 3 жыл бұрын
Can I lock cell after data entry automatically using appscript
@SpencerFarris
@SpencerFarris 3 жыл бұрын
I have another video on "lock cell after edit." Is that what you want?
@markuswinter-cdps3008
@markuswinter-cdps3008 2 жыл бұрын
Thanks so much for the video!! What I'm looking to do is create circa 368 new sheets(tabs) all from the same template that contains protections, as I get the name of each new sheet from a list of cells. I've attached a script on how to make multiple new sheets from a list, is there a way to combine this with your scripts to have each new sheet be a copy of the template while retaining its protections? Thanks! function makeTabs2() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheetByName("FireDeptList"); var last = sheet.getLastRow();//identifies the last active row on the sheet for (var i = 1; i < last; i++) { var tabName = sheet.getRange(i + 1, 1).getValue();//get the range in column A and get the value. try { if (ss.getSheetByName(tabName) == null) { var create = ss.insertSheet(tabName);//create a new sheet with the value } } catch (err) { Logger.log(err); } } }
@SpencerFarris
@SpencerFarris 2 жыл бұрын
Basically you'd just call my script inside your for loop
@johngraham2250
@johngraham2250 2 жыл бұрын
Could you make it available somewhere I can copy and paste it?
@SpencerFarris
@SpencerFarris 2 жыл бұрын
What do you mean?
@johngraham2250
@johngraham2250 2 жыл бұрын
@@SpencerFarris I mean I want to copy it into a document of mine.
@SpencerFarris
@SpencerFarris 2 жыл бұрын
@@johngraham2250 the script is in the description and you can make a copy of the Sheet
@johngraham2250
@johngraham2250 2 жыл бұрын
@@SpencerFarris how do I make a copy of th Sheet?
@SpencerFarris
@SpencerFarris 2 жыл бұрын
@@johngraham2250 The link is in the description. Open it then File > "Make a copy"
@nathanbaxa9542
@nathanbaxa9542 3 жыл бұрын
Can anyone help me with this. I have tried this with the sheet I need to copy. I keep getting errors when I try to run the script. I have no idea what I am doing wrong!
@SpencerFarris
@SpencerFarris 3 жыл бұрын
Hey Nathan. What errors are you getting?
@nathanbaxa9542
@nathanbaxa9542 3 жыл бұрын
@@SpencerFarris TypeError: Cannot read property 'getSheetByName' of Null - I have watched your video countless times but I am not versed in Scripts at all so I am trying to teach myself this one function!
@SpencerFarris
@SpencerFarris 3 жыл бұрын
@@nathanbaxa9542 Can you post your script here? That's an unusual error for you to be getting.
@phoebeyou7722
@phoebeyou7722 3 жыл бұрын
@@SpencerFarris TypeError: Cannot read property 'getProtections' of null copyWithProtections @Code.gs4
@phoebeyou7722
@phoebeyou7722 3 жыл бұрын
@@SpencerFarris I just copied and pasted your script: function copyWithProtections(){ const sh = SpreadsheetApp.getActiveSpreadsheet(); const ss = sh.getSheetByName("Template"); const prot = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE); let nSheet = ss.copyTo(sh).setName(sh.getNumSheets()-1); let p; for (let i in prot){ p = nSheet.getRange(prot[i].getRange().getA1Notation()).protect(); p.removeEditors(p.getEditors()); if (p.canDomainEdit()) { p.setDomainEdit(false); } } }
@AthwTopspeed
@AthwTopspeed Жыл бұрын
Hi Spenser, it's a great video. I followed your steps but there this error : Exception: The parameters (String) don't match the method signature for SpreadsheetApp.getActiveSpreadsheet. What should I do now?
@SpencerFarris
@SpencerFarris 23 күн бұрын
Sorry it's been SO LONG. Do you still need help?
@ianupagarwal
@ianupagarwal 7 ай бұрын
Hey, this was really helpful. I need another help from you. Can you please share where i cant message you?
@SpencerFarris
@SpencerFarris 7 ай бұрын
My email is in the description
@nathanandrebulatao8763
@nathanandrebulatao8763 2 жыл бұрын
What if they use Make a Copy in file tab?
@SpencerFarris
@SpencerFarris 2 жыл бұрын
There is nothing you can do to change the behavior of menu items. This method only works using the custom function.
@angiesalazar2364
@angiesalazar2364 2 жыл бұрын
Is there any chance that I can make a worksheet name that increments as month names?
@SpencerFarris
@SpencerFarris 2 жыл бұрын
Sure, but there's not enough in your description to build anything
@angiesalazar2364
@angiesalazar2364 2 жыл бұрын
@@SpencerFarris Instead of 1,2,3.... as names of the worksheet, can it be January, February, etc...
@SpencerFarris
@SpencerFarris 2 жыл бұрын
@@angiesalazar2364 Sure, not sure what help you're asking for
@Lionxdanger
@Lionxdanger 2 жыл бұрын
Hey I am having a bit of trouble doing this can you help me out?
@SpencerFarris
@SpencerFarris 2 жыл бұрын
Yes, what's up?
@Lionxdanger
@Lionxdanger 2 жыл бұрын
@@SpencerFarris Is it possible to copy permisons even when copying to a whole new spreadsheet that I do not own?
@SpencerFarris
@SpencerFarris 2 жыл бұрын
@@Lionxdanger You must own it
@ammeckamoro1695
@ammeckamoro1695 3 жыл бұрын
hanks for the code
@aayanksrivastava8265
@aayanksrivastava8265 Жыл бұрын
Where I get script google?
@SpencerFarris
@SpencerFarris Жыл бұрын
Extensions > Apps Script
@dt5911
@dt5911 2 жыл бұрын
Hi Spencer, great video, instructions and explanation - I have just subscribed to your channel - even if you have retired from creating new ones. This solution is the opposite of what I need to do. I have a protected sheet, with 153 ranges in exception that can be edited. I need to create 10+ sheets, and working off a tracking point mouse is too fatiguing. If you could help with this I would be grateful. Thanks, DT
@SpencerFarris
@SpencerFarris 23 күн бұрын
I just created a new video for SHEET protections
@wintermelon5639
@wintermelon5639 3 жыл бұрын
i copied the code and cant run it, help
@SpencerFarris
@SpencerFarris 3 жыл бұрын
What error are you seeing?
@streetlight7444
@streetlight7444 2 жыл бұрын
@@SpencerFarris in my situation also here's what error occurred; 8:07:16 AM Error TypeError: Cannot read property 'getProtections' of null copyWithProtections @ Copy of Code.gs:4
@streetlight7444
@streetlight7444 2 жыл бұрын
@@SpencerFarris I have to finish the setup for my business. help me please. it seems not working in current updates, maybe?
@SpencerFarris
@SpencerFarris 2 жыл бұрын
@@streetlight7444 Don't run the function manually, it runs automatically whenever an edit occurs
@streetlight7444
@streetlight7444 2 жыл бұрын
@@SpencerFarris oh.. So I don't need to run it repeatedly.. thanks
@wut-m9kbro
@wut-m9kbro 2 ай бұрын
update plssss 2024
@SpencerFarris
@SpencerFarris Ай бұрын
WDYM?
@movesmartlynow
@movesmartlynow 2 жыл бұрын
Hi Spencer ... I am your Channel Subscriber & just sent you email with Subject "Need Support" .. Kindly help..
Google Sheets: Create and Populate a Sales Tracker
12:35
Spencer Farris
Рет қаралды 3,2 М.
Protect the Same Range of All Tabs
8:49
Spencer Farris
Рет қаралды 5 М.
If people acted like cats 🙀😹 LeoNata family #shorts
00:22
LeoNata Family
Рет қаралды 33 МЛН
How to Copy a Row to another Sheet with Google Apps Script
15:18
Google Sheets - Clear Contents, Keep Formulas
8:15
Learn Google Sheets & Excel Spreadsheets
Рет қаралды 99 М.
Google Sheets - Protect or Totally Hide Data Using IMPORTRANGE
7:27
Prolific Oaktree
Рет қаралды 32 М.
IMPORTRANGE Function in Google Sheets | Multiple Sheets
10:11
Leila Gharani
Рет қаралды 390 М.
Google Sheets | How to Reference Cells in Other Sheets
11:21
Prolific Oaktree
Рет қаралды 60 М.
Google Sheets Tips and Tricks for 2024
8:08
proflead
Рет қаралды 12 М.
IMPORTRANGE tips and errors - Google SHEETS
13:19
Practical Sheets
Рет қаралды 37 М.