Below is my code:
delCol
tracks how many columns have been deleted (to keep the iterations aligned)
sheet
is the active spreadsheet
data
is the array of values from the row I'm searching through, retrieved via SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("2:2").getValues();
function deleteRows() {
var delCol = 0;
var data = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("2:2").getValues();
var sheet = SpreadsheetApp.getActiveSheet();
for(var i = 0; i < data[0].length; i++) {
if(data[0][i-delCol].indexOf("txt-to-delete") > -1 || data[0][i-delCol] == ""){
sheet.deleteColumn(i - delCol + 1);
delCol++;
}
}
}
When I run this code, each and EVERY column is deleted.