Last active
October 11, 2021 21:11
-
-
Save jonathonbyrdziak/fdfc041962462df589d0d6f99356125e to your computer and use it in GitHub Desktop.
Quick Edits in Google Sheets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function LISTWALKER(columnsRange) { | |
var columnArray = []; | |
var rowArray = []; | |
for (var i = 0; i <= columnsRange - 1; i++) { | |
columnArray = columnsRange[i]; | |
for (var j = 0; j <= columnArray - 1; j++) { | |
rowArray = columnArray[i]; | |
} | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createSearchAndDestroyMenu() { | |
var menu = SpreadsheetApp.getUi().createMenu("QuickEdits"); | |
menu.addItem("Search and Destroy", "searchAndDestroyPrompt"); | |
menu.addToUi(); | |
} | |
function searchAndDestroyPrompt() { | |
Logger.log("running"); | |
var ui = SpreadsheetApp.getUi(); | |
var result = ui.prompt("Search A column and delete what?"); | |
//Get the button that the user pressed. | |
var button = result.getSelectedButton(); | |
if (button === ui.Button.OK) { | |
Logger.log("The user clicked the [OK] button."); | |
Logger.log(result.getResponseText()); | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
var rows = sheet.getDataRange(); | |
var numRows = rows.getNumRows(); | |
var values = rows.getValues(); | |
var rowsDeleted = 0; | |
var row = ''; | |
var toDelete = ''; | |
for (var i = 0; i <= numRows - 1; i++) { | |
row = values[i]; | |
var cellString = row[0]+''; | |
if (cellString.indexOf(result.getResponseText())>-1) { | |
toDelete += row[0]+"\n"; | |
} | |
} | |
//ui.alert(rowsDeleted+" rows found and deleted."); | |
var confirmResult = ui.alert( | |
'Please confirm', | |
"Are you sure you want to delete these rows?\n\n"+toDelete, | |
ui.ButtonSet.YES_NO); | |
// Process the user's response. | |
if (confirmResult == ui.Button.YES) { | |
var row = ''; | |
for (var i = 0; i <= numRows - 1; i++) { | |
row = values[i]; | |
// This searches all cells in columns A (change to row[1] for columns B and so on) | |
// and deletes row if cell is empty or has value 'delete'. | |
var cellString = row[0]+''; | |
if (cellString.indexOf(result.getResponseText())>-1) { | |
sheet.deleteRow((parseInt(i)+1) - rowsDeleted); | |
rowsDeleted++; | |
} | |
} | |
ui.alert(rowsDeleted+' rows destroyed.'); | |
} else { | |
// User clicked "No" or X in the title bar. | |
Logger.log("The user canceled the delete process"); | |
} | |
} else if (button === ui.Button.CLOSE) { | |
Logger.log("The user clicked the [X] button and closed the prompt dialog."); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment