Google Sheets: Copy With Protections

Поделиться
HTML-код
  • Опубликовано: 8 сен 2024
  • How to copy a sheet with its protections.
    Important note:
    * You cannot just call prot[i].getRange() because the range value includes data about the sheet it's protecting, not just the row/column or A1 notation value. Make sure to call prot[i].getRange().getA1Notation() so it runs correctly.
    Sheet (to copy):
    docs.google.co...
    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);
    }
    }
    }

Комментарии • 171

  • @johngraham2250
    @johngraham2250 Год назад +3

    This is brilliant! Can't believe not everybody uses this in their spreadsheets.

  • @juliajones5948
    @juliajones5948 Месяц назад +1

    THANK YOU!!!!!!!! This is exactly what I needed. What if you want to duplicate a whole notebook with protections?

  • @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!

  • @kmac33PS5
    @kmac33PS5 2 года назад +1

    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.

  • @streetlight7444
    @streetlight7444 2 года назад +3

    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?

  • @TheCraftyBrick
    @TheCraftyBrick Год назад +1

    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  Год назад +2

      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 Год назад +1

      @@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  Год назад +1

      @@TheCraftyBrick Yes :)

  • @yvettefraga9809
    @yvettefraga9809 2 года назад

    Thank you so much! You just save me and my team a ton of time!

  • @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?

  • @user-qv3qv4zv7o
    @user-qv3qv4zv7o 8 месяцев назад +1

    How would I edit this code to include both RANGE and SHEET permissions?

    • @avinashbiju5329
      @avinashbiju5329 2 месяца назад

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

  • @thebeautyfood
    @thebeautyfood Год назад +2

    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 4 месяца назад

      Do you make it? Need help here

  • @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.

  • @Fr3onYTB
    @Fr3onYTB 2 года назад

    Hey Spencer Thank you for your video and help

  • @user-rs7tm8oi7i
    @user-rs7tm8oi7i 3 месяца назад

    @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  3 месяца назад

      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

  • @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  Год назад +1

      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

  • @K1LLA_KING_KONG
    @K1LLA_KING_KONG 2 месяца назад

    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  Месяц назад

      I honestly need to make another video with that

  • @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?

  • @GorillaVape-ui4nd
    @GorillaVape-ui4nd 2 месяца назад

    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  Месяц назад

      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

  • @jayhive4884
    @jayhive4884 9 месяцев назад

    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  9 месяцев назад

      Do you get an error message, or just forever loading?

  • @ammeckamoro1695
    @ammeckamoro1695 3 года назад +1

    hanks for the code

  • @JosephSalonga
    @JosephSalonga 2 месяца назад

    i cannot press the run button what do you think is the problem?

  • @setyawana.5519
    @setyawana.5519 4 месяца назад

    TypeError: Cannot read properties of null (reading 'getSheetByName')
    why??

    • @SpencerFarris
      @SpencerFarris  4 месяца назад

      Hm, not sure. Can you post your code here and I'll look.

  • @md.nazmulhossain8690
    @md.nazmulhossain8690 3 месяца назад

    Dear,
    I share my file with another coworker. He wants to duplicate this file. How does he do this?

  • @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?

  • @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 ?..

  • @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.

  • @VIJAYAMIRTHARAJPROMINANCE
    @VIJAYAMIRTHARAJPROMINANCE 2 месяца назад

    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  Месяц назад

      Yes, you need to use an Installed Trigger instead so that you can make it run as the sheet owners

  • @amirrostam318
    @amirrostam318 Год назад

    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?

  • @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

  • @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

  • @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 года назад +1

      @@SpencerFarris Thanks. Appreciated.

  • @theeretailtherapist_
    @theeretailtherapist_ Год назад

    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  Год назад +1

      Extensions > Apps Script
      Delete what's there, paste this

    • @theeretailtherapist_
      @theeretailtherapist_ Год назад

      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  11 месяцев назад

      ​@@theeretailtherapist_If someone makes a copy of a document THEY are they owner, not you, so protections wouldn't do anything there.

  • @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  Год назад +1

      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

  • @MrScoredance
    @MrScoredance 4 месяца назад

    Hi Spencer. Can you help me? How to protect SHEET instead RANGE?

    • @MrScoredance
      @MrScoredance 4 месяца назад

      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  4 месяца назад

      The code for protecting a sheet does work a bit differently. What have you tried?

    • @MrScoredance
      @MrScoredance 4 месяца назад

      @@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
      }

  • @kristellekaygloria5728
    @kristellekaygloria5728 2 года назад

    How to restrict someone from making a copy of my entire spreadsheet in google sheets?
    Thanks.

    • @SpencerFarris
      @SpencerFarris  2 года назад +1

      Give them view access and toggle "Viewers cannot make copies."
      Editors cannot be prevented from making a copy.

  • @elbegzayaoyungerel1523
    @elbegzayaoyungerel1523 2 года назад +1

    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 года назад +1

      Don't run the script, it runs automatically whenever an edit occurs.

    • @Cryostatic
      @Cryostatic Год назад

      @@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 Год назад

      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 Год назад

      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  Год назад

      ​@@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

  • @ryanpeterson7998
    @ryanpeterson7998 3 года назад

    does this also work when you copy the entire document and rename? 2020-12-09 copied to new document 2020-12-10?

  • @rajeshat9353
    @rajeshat9353 2 года назад

    @spencer, is it possible to protect selected sheets, same range in a google sheet file

    • @SpencerFarris
      @SpencerFarris  2 года назад +1

      Yes, though I don't have that written up at present

  • @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  11 месяцев назад

      On Edit functions run automatically whenever an edit is made.

    • @SpencerFarris
      @SpencerFarris  11 месяцев назад

      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 11 месяцев назад

      @@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"

  • @Jumisco
    @Jumisco Год назад

    how to copy protection sheet wit exeption some range?

  • @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

  • @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

  • @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

  • @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 года назад +1

      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

  • @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 года назад +1

      Basically you'd just call my script inside your for loop

  • @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?

  • @wut-m9kbro
    @wut-m9kbro 3 дня назад

    update plssss
    2024

  • @ianupagarwal
    @ianupagarwal 5 месяцев назад

    Hey, this was really helpful. I need another help from you. Can you please share where i cant message you?

    • @SpencerFarris
      @SpencerFarris  5 месяцев назад

      My email is in the description

  • @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?

  • @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.

  • @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?

  • @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 11 месяцев назад

      @@SpencerFarrisyes, yes, can you please suggest that -- I am not able to get that to work

    • @SpencerFarris
      @SpencerFarris  11 месяцев назад

      @@tusharagarwal2657 Sorry, suggest what?

  • @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

  • @aayanksrivastava8265
    @aayanksrivastava8265 Год назад

    Where I get script google?

  • @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

  • @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);
      }
      }
      }

  • @johngraham2250
    @johngraham2250 Год назад

    Could you make it available somewhere I can copy and paste it?

    • @SpencerFarris
      @SpencerFarris  Год назад

      What do you mean?

    • @johngraham2250
      @johngraham2250 Год назад

      @@SpencerFarris I mean I want to copy it into a document of mine.

    • @SpencerFarris
      @SpencerFarris  Год назад

      @@johngraham2250 the script is in the description and you can make a copy of the Sheet

    • @johngraham2250
      @johngraham2250 Год назад

      @@SpencerFarris how do I make a copy of th Sheet?

    • @SpencerFarris
      @SpencerFarris  Год назад +1

      @@johngraham2250 The link is in the description. Open it then File > "Make a copy"

  • @wintermelon5639
    @wintermelon5639 2 года назад

    i copied the code and cant run it, help

    • @SpencerFarris
      @SpencerFarris  2 года назад

      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

  • @yogaworld12
    @yogaworld12 2 года назад

    Hi Spencer ... I am your Channel Subscriber & just sent you email with Subject "Need Support" .. Kindly help..