gpt-4-0314· openai
Suzhen/CodeChat
Please try composing this google sheets script, called clearURL. It checks the leftmost…
- User
Please try composing this google sheets script, called clearURL. It checks the leftmost cell in every row. If that cell's value ends with "day" or "ime" it does nothing and iterates to the next row. Otherwise, it deletes the values in columns D, I, N, and S and iterates to the next row. Please make an effort to minimize execution time.
- Assistant
function clearURL() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var lastRow = sheet.getLastRow(); var range = sheet.getRange(1, 1, lastRow, 20); // Assuming there are a total of 20 columns in the sheet var values = range.getValues(); for (var i = 0; i < values.length; i++) { var value = values[i][0].toString(); if (value.endsWith("day") || value.endsWith("ime")) { // Do nothing } else { // Clear values in columns D, I, N, and S values[i][3] = ""; // Column D values[i][8] = ""; // Column I values[i][13] = ""; // Column N values[i][18] = ""; // Column S } } // Update the range with the new values range.setValues(values); }This script efficiently clears the necessary cells in columns D, I, N, and S by iterating through each row only once and minimizing the calls to the Google Sheets API.