我有以下脚本,通过脚本插入公式,以便在电子表格中输入数据时运行计算。最后一行显然不起作用,但我想知道是否有一个典型的RoundUp函数包含在像Net Height Calculation一样的公式中。谢谢你的任何建议。
function MH484020() {
//Grab the active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
//Find the first last row with data in it
var lastrow = sheet.getLastRow();
//Use the last row with data in it to place forumulas below it
var range = sheet.getRange(lastrow+1,2);
range.setValue('DRAINAGE STR. 48-4020')
var range = sheet.getRange(lastrow+1,3)
range.setValue('484020')
//Set data validation for steps or not
var range = sheet.getRange(lastrow+1,4);
var rule = SpreadsheetApp.newDataValidation().requireValueInList(['Yes','No'])
.build();
range.setDataValidation(rule);
//Covers Calculation
sheet.getRange(lastrow+1,7).setFormula("=F" + (lastrow+1));
//Net Height Calculation
sheet.getRange("H" + (lastrow+1)).setFormula("=E" + (lastrow+1) + "-(F" + (lastrow+1) + "*1.5)");
//Mastic Calculation
sheet.getRange(lastrow+1,9).setFormula("=Roundup"( + "H" + (lastrow+1)));
}
答案 0 :(得分:1)
你在错误的地方有一些引用
sheet.getRange(lastrow+1,9).setFormula("=Roundup(H" + (lastrow+1) + ")");
如果您遇到此类问题,请先按照惯例将公式放入单元格中,并确保计算正确。然后复制公式并将其粘贴到paranthesis setFormula()
之间.setFormula(=E5-(F5*1.5));
接下来在公式的开头和结尾加上引号
.setFormula("=E5-(F5*1.5)");
接下来用以下代码替换每个行号:(包括引号)
" + (lastrow+1) + "
如:
.setFormula("=E" + (lastrow+1) + "-(F" + (lastrow+1) + "*1.5)");
如果行号结束公式,那么你应该省略结束加号并引用。
=E5-F5
.setFormula("=E" + (lastrow+1) + "-F" + (lastrow+1));