简体   繁体   English

如果单元格范围内的值不在两个数字之间,则硬停止

[英]Hard stop if a value in a range of cells is not between 2 numbers

I have a page where my team could enter data into one page and then hit a save button, then it would copy and paste the data into a database file then clear the contents of the original page. 我有一个页面,团队可以在其中输入数据,然后单击保存按钮,然后它将数据复制并粘贴到数据库文件中,然后清除原始页面的内容。 What I'm trying to figure out is how I can hard stop the save if the pasted information is incorrect. 我要弄清楚的是,如果粘贴的信息不正确,我将如何立即停止保存。 example. 例。 they copied the incorrect information from the one program we use and paste it into the spreadsheet. 他们从我们使用的一个程序中复制了错误的信息,并将其粘贴到电子表格中。 but the customer number is in the wrong cell. 但是客户编号在错误的单元格中。 This would skew the information in the database. 这会使数据库中的信息倾斜。

So my thoughts were to have a criteria check of some sort. 所以我的想法是要进行某种标准检查。 So it would check the data in a specific column of cells and check to see if it were between 10000 and 99999 or check to ensure it has 5 digits. 因此它将检查单元格的特定列中的数据,并检查其是否在10000和99999之间,或检查以确保其具有5位数字。 then have a second check for something similar. 然后再次检查类似的东西。

It would be better if I can find a way to have a Paste button that could paste the information and have the hard stop within that code. 如果我能找到一种粘贴按钮来粘贴信息并在代码中进行严格停止的方法,那将更好。 But baby steps... 但是婴儿的脚步...

function Copy() {
var sss = SpreadsheetApp.openById('file name here'); 
var ss = sss.getSheetByName('InputData');
var range2 = sss.getRange('D8:O1000');
var range = ss.getRange('A8:Q1000');
var data = range.getValues();
var tss = SpreadsheetApp.openById('file name here');
var ts = tss.getSheetByName('OutOfStockData');
ts.getRange(ts.getLastRow()+1, 1, data.length, data[0].length).setValues(data);
range2.clearContent();
}

Any help would be greatly apricated. 任何帮助都会大大增加。

Thanks. 谢谢。

EDIT. 编辑。 I'm unable to use forms as we copy the information from an internal WMS program we use. 我无法使用表格,因为我们从使用的内部WMS程序复制信息。 When we copy the information, it gets copied in a format that is recognized by any spreadsheet. 当我们复制信息时,将以任何电子表格均可识别的格式复制信息。 So we would just copy and paste into the spreadsheet and then add any extra information needed to each line in the extra columns. 因此,我们只需将其复制并粘贴到电子表格中,然后将所需的任何额外信息添加到额外列中的每一行。 (ie. comment column.) The checks needed is so I can get accurate information on Stockouts. (即评论栏。)需要进行检查,以便我可以获得有关缺货的准确信息。 Sometimes an error can be made when one of my teammates copies information from a different window in WMS. 有时,当我的一个队友从WMS的另一个窗口复制信息时,可能会出错。 so one check like mentioned before would be customer number which is always in column J. and never more than 99999 or less then 10000. another check could be the Case ID which is always in column D which is never more then 9999999 and less then 1000000. verifying these two columns could prevent the data from being skewed if the wrong information is copied from WMS. 因此,前面提到的一张支票将是客户编号,该客户编号始终在J列中,并且永远不会超过99999或更少,然后是10000。另一张支票可能是Case ID,它始终在D列中,其永远不会超过9999999并且少于1000000如果从WMS复制了错误的信息,则验证这两列可以防止数据偏斜。

So the Information gets Copied from WMS, Pasted into InputData, then when the added information gets entered I would click the save button and it would take all the data in the inputData sheet and copy it into the outofstockdata sheet where It would be used for other metric data needed. 因此,从WMS复制信息,将其粘贴到InputData中,然后在输入添加的信息时,单击保存按钮,它将获取inputData表中的所有数据并将其复制到outofstockdata表中,该表将用于其他所需的指标数据。

As far as the Paste button, Some of the guys who would need to use this sheet are not very computer literate. 就“粘贴”按钮而言,一些需要使用此工作表的人不太懂计算机。 So the goal would be to have them press said Paste button and the information from our WMS program which would be on the clipboard within windows(no different than copying and pasting from an email to a word document). 因此,目标是让他们按下“粘贴”按钮,然后从WMS程序中获得信息,这些信息将位于窗口内的剪贴板中(与从电子邮件复制和粘贴到Word文档一样)。 which we have copied earlier be pasted into the Frist sheet where we would comment. 我们之前复制的内容将粘贴到“ Frist”表中,以便我们进行评论。

Thanks. 谢谢。

To hard stop an script that met a condition use return . 要硬停止满足条件的脚本,请使用return This could be shown with vanilla JavaScript 可以使用香草JavaScript来显示

 function myFunction(){ var upperLimit = 10; var lowerLimit = 5; var input = prompt('Give me a value'); // This is the condition that will hard stop the script. var condition = input >= lowerLimit && input <= upperLimit; if (condition){ return; // This hard stop the script. } else { //if the condition is not met, continue myFunction(); } } myFunction(); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM