So I am creating a sheet to track some data, and I have it fed into a chart via a ratio and a date, so for instance, I had 10 and 5 equals a ratio of 2, at this particular time. I was able to find a script to automate the date, but I also wanted to automate the ratio, as every time I have to put in cell reference/ cell reference. Sure its just shift click and drag but I would like it to be automated just like the date. I have been teaching myself javascript but I am still VERY new. Basically I came up with this.
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Overall", "M&K", "Con" ) {
var r = s.getActiveCell();
if( r.getColumn() == 2 ) { //checks that the cell being edited is in column B
var nextCell = r.offset(0, -2);
if( nextCell.getValue() === '' ) //checks if the adjacent cell is empty or not?
nextCell.setValue(new Date()).setNumberFormat("dd/MM/yyyy, hh:mm");
}
}
}
function onEdit() {
var s1 = SpreadsheetApp.getActiveSheet();
if( s1.getName() == "Overall", "M&K", "Con" ) {
var r1 = s1.getActiveCell();
if( r1.getColumn() == 3 ) { //checks that the cell being edited is in column C
var a = r1.offset(0, 1);
var b = r1.offset(0, -1);
var c = r1.offset(0, 0);
if( a.getValue() === '' ) //checks if the adjacent cell is empty or not?
a.setValue(b.getValue()/c.getValue());
}
}
}
And when I put this into my one sheet, only one will work, not both, and its always the bottom one, and nothing will work if I try and put it first. I'm sure it has something to do with how the script is structured but I honestly have no idea.
I tried changing around the values and restructuring it to the best of my knowledge and ability, but I could never get two to run simultaneously, its always either one or the other.