Row Modified timestamp

This is what I ended up using, which has the added benefit of working on all of the sheets, because it only looks for a column with “Modified Date” in the first row (also, it won’t modify the first row):

function onChange(e) {

	const sheet = SpreadsheetApp.getActiveSheet()

	const rowIndex = (function() {
		switch (e.changeType) {
			case "EDIT":
				return sheet.getActiveCell().getA1Notation().replace(/\D/g, "").trim()
			case "INSERT_ROW":
				return sheet.getLastRow()
			default:
				throw new Error(`This function can't handle changeType: ${e.changeType}`)
		}
	})()

	const column = sheet.getDataRange().getValues()[0].indexOf("Modified Date") + 1

	if (rowIndex != 1 && column !== 0)
		sheet.getRange(rowIndex, column).setValue(new Date())
}

NOTE: This works based on a trigger, so after adding this function to the project, you have to create an “On change” trigger to run it.

1 Like