function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Custom Tools')
.addItem('Remove Blank Rows', 'removeBlankRows')
.addToUi();
}
function removeBlankRows() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = sheet.getDataRange();
var values = range.getValues();
var rowsToDelete = [];
// Loop through all rows and check for blank rows
for (var i = values.length - 1; i >= 0; i--) {
var isBlank = values[i].every(function(cell) { return cell === ''; });
if (isBlank) {
rowsToDelete.push(i + 1);
}
}
// Delete rows in reverse order to avoid shifting indices
for (var j = 0; j < rowsToDelete.length; j++) {
sheet.deleteRow(rowsToDelete[j]);
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter