Reputation: 321
Goal:
For example, let's say for the first time, in cell H3, a name called "John A" appears. In this case, I want to be able to add borders to H3:I3. And if "John B" appears below "John A," then I want to add another border to H4:I4. And so on.
For example, if "John B" was automatically removed for cell H4, then I want to also remove the borders for H4:I4. And if "John A" was also removed from cell H3, then I want to also remove the borders for H3:I3.
Current Code: I'm trying to pass parameters from the onEdit() function that's located in another file to the insertDynamicBorders() function as I thought that this would be event triggering matter.
function insertDynamicBorders(row) {
var statusSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Status");
// Columns
dateColumn = 1;
if (row > 16) {
if (statusSheet.getRange("H3") != null ) {
var cell = statusSheet.getRange("H3:I3");
cell.setBorder(true, true, true, true, true, true, "black", SpreadsheetApp.BorderStyle.SOLID);
} else {
var cell = statusSheet.getRange("H3:I3");
cell.setBorder(false, false, false, false, false, false, "black", SpreadsheetApp.BorderStyle.SOLID);
}
if (statusSheet.getRange("H4") != null) {
var cell = statusSheet.getRange("H4:I4");
cell.setBorder(true, true, true, true, true, true, "black", SpreadsheetApp.BorderStyle.SOLID);
} else {
var cell = statusSheet.getRange("H4:I4");
cell.setBorder(false, false, false, false, false, false, "black", SpreadsheetApp.BorderStyle.SOLID);
}
if (statusSheet.getRange("H5") != null) {
var cell = statusSheet.getRange("H5:I5");
cell.setBorder(true, true, true, true, true, true, "black", SpreadsheetApp.BorderStyle.SOLID);
} else {
var cell = statusSheet.getRange("H5:I5");
cell.setBorder(false, false, false, false, false, false, "black", SpreadsheetApp.BorderStyle.SOLID);
}
if (statusSheet.getRange("H6") != null) {
var cell = statusSheet.getRange("H6:I6");
cell.setBorder(true, true, true, true, true, true, "black", SpreadsheetApp.BorderStyle.SOLID);
} else {
var cell = statusSheet.getRange("H6:I6");
cell.setBorder(false, false, false, false, false, false, "black", SpreadsheetApp.BorderStyle.SOLID);
}
if (statusSheet.getRange("H7") != null) {
var cell = statusSheet.getRange("H7:I7");
cell.setBorder(true, true, true, true, true, true, "black", SpreadsheetApp.BorderStyle.SOLID);
} else {
var cell = statusSheet.getRange("H7:I7");
cell.setBorder(false, false, false, false, false, false, "black", SpreadsheetApp.BorderStyle.SOLID);
}
}
}
Issue:
Upvotes: 0
Views: 5274
Reputation: 6062
When using Apps Script triggers, more particularly the onEdit
, it is important to note the following:
onEdit(e)
runs when a user changes a value in a spreadsheet.Script executions and API requests do not cause triggers to run. For example, calling
Range.setValue()
to edit a cell does not cause the spreadsheet'sonEdit
trigger to run.
Taking the above into account then, what you want cannot be directly achieved.
What you can do in this situation is to make use of the installable triggers and create a time driven trigger. You can create a script which will check for any changes which occur in your spreadsheet compared to the previous version. Since this will have to be done programmatically by you, it is a more cumbersome bypass.
Another option (making use of the time driven trigger still) is to check which is the
last row in the columns H
and I
(as per your example) and also considering the fact that only the wanted values get inserted into these columns.
Upvotes: 1