Forum Discussion

ArchieSmith's avatar
ArchieSmith
Copper Contributor
Dec 22, 2022
Solved

Office Script If Statement not working

Hi everyone!   Apologies for my likely simple problem, I have little experience with coding but I'm trying my best to learn how to automate my Excel spreadsheets.   My if statement doesn't seem t...
  • Lorenzo's avatar
    Dec 22, 2022

    ArchieSmith 

    After a bit of reading could you try the following:

    function main(workbook: ExcelScript.Workbook) {
      let wsArr = workbook.getWorksheets();
      wsArr.forEach(ws => {
        let range = ws.getRange("A4");
        let rangeval = range.getValue();
        if (rangeval == 'X') {
            console.log('Yes');
          } else {
            console.log('No');
          }
        }
      )
    }

Resources