How to Automatically Clear Data from Google Sheets

Поделиться
HTML-код
  • Опубликовано: 9 янв 2023
  • In this video I explain how to set up a process using Google Apps Script so data in Google Sheets can be automatically deleted from the sheet on a scheduled frequency without the need for you to log into Google Drive or Google Sheets.
    The code I use in this video is pasted below so you can easily copy it:
    function clearTheSheet () {
    var app = SpreadsheetApp;
    var activeSheet = app.getActiveSpreadsheet().getActiveSheet();
    activeSheet.getRange("A1:F500").clearContent();
    }

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

  • @gunsnjesus6107
    @gunsnjesus6107 3 месяца назад

    How can I get certain entries that have a specific date attached to delete .
    Example it’s a parking list and today is the first they want to park for 3 days should expire 5/4 , how do i make sure it deletes on 5/5

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

    Very clear, thanks. By the way, you fuzzed out most of your email addresses, but some still remain, for example around 6:42

  • @user-cw8nn9lc5i
    @user-cw8nn9lc5i Год назад

    this was amazing and super helpful, I am a team leader and I'm using a shift schedule for meal breaks and some other stuff, we use dropdown menus to select the name of agent and when he has the meal break, now, I am using this script to clear the agent names from the dropdowns after shift end(for the next shift leader to input the agent names for the meal break hours) instead of clearing I wanted to rather select a certain option in the drop down menu, that option is named "free slot" on my end, currently the script deletes/clears that dropdown showing as blank , can it set a certain option in a dropdown menu for example every day at 4AM to select the "free slot" option in the dropdown menu on a specific range of cells, can you help me with this ? I am struggling to find out a way but I am very stuck :(

  • @dankiet4397
    @dankiet4397 7 месяцев назад

    i have many files google sheet. so, i wanna copy & paste script+trigger to others files sheet? how to make easily?

  • @ezequielrevollo8136
    @ezequielrevollo8136 Месяц назад

    Great Video

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

    Thank you so much! I need to do this, but across multiple tabs/sheets. What do I need to add to the script to make that happen? I used the script you presented with the range I needed, but it is only deleting the data from the 1st sheet.

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

      Hi, if you have a tab that you want to clear and lets say it is just called Sheet2 then you just change line 3 of that code from var activeSheet = app.getActiveSpreadsheet().getActiveSheet(); to var activeSheet = app.getActiveSpreadsheet().getSheetByName("Sheet2"); So basically change the getActiveSheet() part to getSheetByName("Sheet Name Here")

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

    Thank you very much! I think is the script I will use, but I don't know how to implement it in a sheet where I will show upcoming event, where for example in C1 I will enter today's date and from row A2 i will enter the event data. When the event is expired, I would like to delete it . Thank you for your precious help.

  • @dankiet3838
    @dankiet3838 3 месяца назад

    hi bro,
    Is there a way to delete multiple files at the same time?

  • @matheusaragao895
    @matheusaragao895 10 месяцев назад

    MAN I LOVE U

  • @dankiet3838
    @dankiet3838 3 месяца назад

    Hi bro,
    Is there a way to delete multiple files at the same time?

  • @pritamchougule9987
    @pritamchougule9987 8 месяцев назад

    Hi bro pls help me here...
    Actually I'm creating automated sheet where i want to delete members from master whose membership is expired I need trigger botton or something else logic can you pls help me

  • @user-rr1gn9uw4d
    @user-rr1gn9uw4d 6 месяцев назад

    On my wndow, extention tab is not appearing in task bar

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

    Thanks a lot, very useful.
    Do you think it would be possible to consolidate the clear function and the importing function into the same consolidated function?

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

      Yes, it should be possible to have the clear function run right before you import new data.

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

    How to get multiple sheets, do i need another code? I try repeating the code but didn´t work. Thanks in advance.

    • @martechhero
      @martechhero  9 месяцев назад +2

      If you are trying to clear multiple sheets with the function you will need to loop through the sheet names. So, for example, if you have 4 sheets and they are called Sheet1, Sheet2, Sheet3, and Sheet4 then this will be the function:
      function clearMultipleSheets() {
      var app = SpreadsheetApp;
      var spreadsheet = app.getActiveSpreadsheet();
      var sheetNames = ['Sheet1', 'Sheet2', 'Sheet3', 'Sheet4'];
      for (var i = 0; i < sheetNames.length; i++) {
      var sheet = spreadsheet.getSheetByName(sheetNames[i]);
      if (sheet) { // Check if the sheet exists before trying to clear content
      sheet.getRange("A1:F500").clearContent();
      }
      }
      }
      Hope that helps.

  • @hidayathullahomeri758
    @hidayathullahomeri758 7 месяцев назад

    thank you very useful, i want one more help i have 2 sheets in same file this function have to apply in both sheets
    function clearthesheet() {
    var range = SpreadsheetApp
    .getActive()
    .getSheetByName("01-yaseen")
    .getRange("G2:M32");
    range.clearContent();
    }
    this function successfully cleared all contents in the range g2:m32 in sheet 01-yaseen ,
    i want to clear the contents of same range in sheet 02-asad also thank you in advance

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

    How to apply by sheet name?

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

      Hi, another person had a similar question but if you have a tab that you want to clear and lets say it is just called Sheet2 then you just change line 3 of that code from var activeSheet = app.getActiveSpreadsheet().getActiveSheet(); to var activeSheet = app.getActiveSpreadsheet().getSheetByName("Sheet2"); So basically change the getActiveSheet() part to getSheetByName("Sheet Name Here")
      Hope that helps.

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

    just wanted to let you know your email was visable when you hovered over it even while blurred because it was at the bottom of the window delete this comment if you want (also 6:45)