I have a Google Sheet where the user can select one of several options in Column A. There are 7 cells within this column where they can select an option. If the user chooses "Omit Day", I need the corresponding column to delete (this gets transferred to a different sheet). I have the following code:
//Delete all cells set to 'Omit Day'.
var omit_vals = [];
var impact_locs = ['A22', 'A23', 'A24','A25', 'A26', 'A27', 'A28'];
var hazard_briefing_placement = ['B13', 'C13', 'D13', 'E13', 'F13', 'G13', 'H13'];
var hazard_date_briefing_placement = ['B12', 'C12', 'D12', 'E12', 'F12', 'G12', 'H12'];
for (var zx = 0; zx < 7; zx++){
var range_omit = String(SpreadsheetApp.getActiveSheet().getRange('main_gen!'+impact_locs[zx]).getValue());
if (range_omit == 'Omit Day'){
omit_vals = zx;
var range_omit_del = body.getRange(hazard_briefing_placement[omit_vals]);
range_omit_del.deleteCells(SpreadsheetApp.Dimension.COLUMNS);
var range_omit_del2 = body.getRange(hazard_date_briefing_placement[omit_vals]);
range_omit_del2.deleteCells(SpreadsheetApp.Dimension.COLUMNS);
Logger.log(omit_vals);
}
}
Omit_vals properly stores the correct value of the column I would like to delete. So with the way the code is currently written, the first time it loops through it deletes the correct column. However, there is now one less column for when it loops through the second time, so when there is a second (or third, or fourth, etc.) column it needs to delete, it now is off by one column due to there being one less to begin with. I am not sure how I can account for this. Any idea of what I need to correct? I am pretty sure it is within the hazard_briefing_placement[omit_vals] line, but I am not sure how to fix this. Thanks!
for (var zx = 0; zx < 7; zx++){tofor (var zx = 6; zx >= 0; zx--){? If this was not the direct solution, I apologize.