1

I searched the official documentation, found this formula ExcelScript.ListDataValidation, but i have no clue how to use it. tried writing this way but no help. Anyone knows how to use this function?

let selectedSheet = workbook.getActiveWorksheet();
const myrange = selectedSheet.getRange("CM4:CM5")
const listvalidation: ExcelScript.ListDataValidation = 
  {
    inCellDropDown:true, 
    source:"yes"
  };
  myrange.setValue(listvalidation)

Appreciate if there is guru out there could guide me a proper way to write the office script data validation list formula.

  • Hey everyone, I have figured it out, use function below const cUpdated = selectedSheet.getRangeByIndexes(firstDataRow, lastCol + 1, lastRow, 1) cUpdated.getFormat().setHorizontalAlignment(ExcelScript.HorizontalAlignment.center); const listvalidation: ExcelScript.DataValidationRule = { list: { inCellDropDown: true, source: "Yes,No" } }; cUpdated.getDataValidation().setRule(listvalidation) – bradleyteoh Nov 17 '22 at 05:31

1 Answers1

0
const sh = workbook.getActiveWorksheet();
const rangeValidates = sh.getRange("A1");
const dv = rangeValidates.getDataValidation();
const listvalidation: ExcelScript.ListDataValidation = {
    inCellDropDown: true,
    source: "yes, no"
};
const listrule: ExcelScript.DataValidationRule = {
    list: listvalidation
};
dv.setRule(listrule);
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 13 '23 at 18:24
  • You should add explanation. – Super Kai - Kazuya Ito Jun 14 '23 at 01:40