简体   繁体   中英

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.

Eg A2 = Pittsburgh, B2=Philadelphia, F2 is a dropdown for either "Pittsburgh" or "Philadelphia". A116=CAROLINA, B116=PHILADELPHIA, then F116 should be a dropdown for either "CAROLINA", or "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.

If 'cellInF' references the current cell in focus, then

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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