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

onEdit trigger causes updated date to be returned as a number

$
0
0

I currently have a Google script bound to my spreadsheet using an onEdit trigger to allow multiple dropdowns.

However, it is affecting my columns with dates, changing them from date format "DD/MM/YYYY" to a 5-digit number

Please let me know what I need to add to the script to stop the format from changing to Automatic.

Also, my code isn't great, I had to copy and paste and play with it to make it work, and I didn't know how to apply it to specific ranges on specific sheets, so applies to all of them. I don't know if this is causing my issue.

To note, the date columns on each sheet are different (Sheet 1 is Column 16 and 17, Sheet 2 is 6, etc.)

My Code:

function onEdit(e) {  var oldValue;  var newValue;  var ss=SpreadsheetApp.getActiveSpreadsheet();  var activeCell = ss.getActiveCell();  if(activeCell.getColumn() == 4,5,6,7,9,10,11,18 && ss.getActiveSheet().getName()=="Sheet 1", "Sheet 2", "Sheet 3", "Sheet 4") {      newValue=e.value;      oldValue=e.oldValue;      if(!e.value) {        activeCell.setValue("");       } else {        if (!e.oldValue) {          activeCell.setValue(newValue);        } else {          activeCell.setValue(oldValue+', '+newValue);        }     }  }}

Viewing all articles
Browse latest Browse all 9782

Trending Articles



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