Last active
January 7, 2020 10:17
-
-
Save bentech/ac0fb587251a3f94d7d73a27c324c41e to your computer and use it in GitHub Desktop.
Add column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test(){ | |
var info = {}; | |
info["value"] =-1; | |
info["range"] = SpreadsheetApp.getActiveSheet().getRange(3,4); | |
info["source"] = SpreadsheetApp.getActiveSpreadsheet(); | |
doEdit(info); | |
} | |
function doEdit(eventInfo) { | |
var sheet = SpreadsheetApp.getActiveSpreadsheet(); | |
var stockInfo = Number(eventInfo.value); | |
var editRange = eventInfo.range; | |
var col = editRange.getColumn(); | |
var sheetId = sheet.getActiveSheet().getIndex(); | |
if( isNaN(stockInfo) && stockInfo !== '' ){ | |
if(sheet) | |
sheet.toast("You have enetered something that isn't a number", "Warning", 3); | |
return; | |
} | |
if(editRange.getWidth() != 1 || editRange.getHeight() != 1){ | |
return; | |
} | |
if(editRange.getRow() < 2){ | |
return; | |
} | |
//A=1, B=2, C=3, D=4, E=5, F=6, G=7, H=8, I=9, J=10, K=11 | |
if( | |
// | |
// EDIT BELOW | |
(sheetId == 1 && (col == 4)) | |
|| (sheetId == 2 && (col == 4 || col == 6)) | |
// STOP EDITING | |
// | |
){ | |
var originalCell = editRange.offset(0,-1); | |
var original = Number(originalCell.getValue()); | |
var add = Number(eventInfo.value); | |
originalCell.setValue(original+add); | |
editRange.setValue(''); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment