Skip to content

Instantly share code, notes, and snippets.

@tuyendq
Last active October 18, 2023 16:42
Show Gist options
  • Save tuyendq/c2dac35e0f5753d6a1b5077ee5ae4de7 to your computer and use it in GitHub Desktop.
Save tuyendq/c2dac35e0f5753d6a1b5077ee5ae4de7 to your computer and use it in GitHub Desktop.
Google Sheets commonly used functions
/**
* Delete columns and rows
*/
function DeleteColumnsAndRows() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName("SHEET-NAME-HERE");
// sheet.getRange(1, 2, sheet.getMaxRows(), sheet.getMaxRows()).activate();
// Delete column B to max
if (sheet.getMaxColumns() > 1) {
sheet.deleteColumns(2, sheet.getMaxColumns()-1);
}
// Delete row 2 to max
if (sheet.getMaxRows() > 1) {
sheet.deleteRows(2, sheet.getMaxRows()-1);
}
};
// Get value from "Price" sheet, 'N2' cell
var cellValue = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Price").getRange('N2').getValue();
// Logger.log(cellValue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment