简体   繁体   English

根据Google电子表格中的相邻单元格进行数据验证

[英]data validation based on adjacent cells in a google spreadsheet

The sheet I am using is here . 我正在使用的工作表在这里

I want to take the validation in column F, Row 2, and apply it to all rows of column F based on the respective values in columns B and C for each row. 我想在F列第2行中进行验证,并根据每行的B列和C列中的相应值将其应用于F列的所有行。

Eg A2 = Pittsburgh, B2=Philadelphia, F2 is a dropdown for either "Pittsburgh" or "Philadelphia". 例如,A2 =匹兹堡,B2 =费城,F2是“匹兹堡”或“费城”的下拉列表。 A116=CAROLINA, B116=PHILADELPHIA, then F116 should be a dropdown for either "CAROLINA", or "PHILADELPHIA". A116 = CAROLINA,B116 = PHILADELPHIA,则F116应该是“ CAROLINA”或“ PHILADELPHIA”的下拉列表。

I found this example script that will copy just the validation, however I will need to add a counter to increment each source cell in the validation for each row that it applies to. 我发现此示例脚本仅复制验证,但是我将需要添加一个计数器,以增加验证所适用的每一行的每个源单元格。

Am I missing something: isn't this just a matter of writing a script which will create a validation rule referencing the list range consisting of the adjacent cells in column A and B relative to the cell in column F. 我是否缺少某些东西:这不仅仅是编写脚本来创建一个验证规则的问题,该脚本将引用列表范围,该范围由相对于F列的A列和B列中的相邻单元格组成。

If 'cellInF' references the current cell in focus, then 如果“ cellInF”引用当前焦点所在的单元格,则

   var validList = cellInF.offset(0,-5,1,2);
   var rule = SpreadsheetApp.newDataValidation().requireValueInRange(validList, true).setAllowInvalid(false).build();
   cellInF.setDataValidation(rule);

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

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