Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

How to insert timestamp when using either of the Fill Color tool or the Paint Format tool

$
0
0

I have been using the code below to insert a timestamp in column L when a cell fill color in column C is changed to white.

The code is working well, but while it works when I choose the white color with the Fill Color paint bucket tool, it does not work when I use the Paint Format paint roller tool.

How do I make the code work with both of these tools?

doubleunary's answer

Google Sheet

/*** Inserts a timestamp when a cell is formatted by choosing a fill color.* Runs on an installable 'on change' trigger.* https://developers.google.com/apps-script/guides/triggers/installable** @param {Object} e The 'on change' event object.*/function insertTimestampOnFormatChange(e) {  // version 1.0, written by --Hyde, 28 October 2021  const settings = {    sheetsToWatch: /^(Sheet1|Sheet2|Sheet3)$/i,    colorsToWatch: /^(#ffffff)$/i,    columnsToWatch: /^(3)$/i, // column C    timestampColumn: 12, // column L    timestampFormat: 'MM-dd-yyyy HH:mm:ss',  };  if (!e) {    throw new Error('Please do not run the script in the script editor window. '+'It runs automatically when you hand edit the spreadsheet.');  }  if (e.changeType !== 'FORMAT') {    return;  }  const sheet = SpreadsheetApp.getActiveSheet();  if (!sheet.getName().match(settings.sheetsToWatch)) {    return;  }  const range = sheet.getActiveRange();  if (!String(range.getColumn()).match(settings.columnsToWatch)) {    return;  }  const now = new Date();  const rowStart = range.getRow();  const colors = range.offset(0, 0, range.getHeight(), 1).getBackgrounds().flat();  colors.forEach((color, rowIndex) => {    if (color.match(settings.colorsToWatch)) {      sheet.getRange(rowStart + rowIndex, settings.timestampColumn)        .setValue(now)        .setNumberFormat(settings.timestampFormat);    }  });}

Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>