I'm trying to insert a timestamp into a cell in column B that has the same row index as the edited or pasted value in column C. Also, I only want to insert a timestamp in an empty cell in column B, while the skip cell already has a timestamp.
This code works correctly whether I edit a cell in column C or paste a value in column C when all cells in column B are empty.
This code has issues with overwriting or not writing values when pasting multiple cells. Kindly help me in editing it.
Here is sample sheet: insert timestamp - multi cell - check blank cell
function insert_timestamp(e)
{
var s = SpreadsheetApp.getActiveSheet();
var cell = s.getActiveCell();
var r = e.range;
var firstRow = r.getRow();
var numRows = r.getNumRows();
var firstCol = r.getColumn();
var lastCol = r.getLastColumn();
var datecell = s.getRange(cell.getRowIndex(), 2);
if((firstCol == 3 || lastCol == 3) && s.getName() == 'test' && datecell.isBlank()) {
var destRange = s.getRange(firstRow, 2, numRows);
var dates = new Array(numRows).fill([new Date()]);
destRange.setValues(dates).setNumberFormat("MM/dd/yyyy hh:mm:ss");
}
}