Dec 22 2022 02:54 AM
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 to want to work in office script the way I want it to and I cant work out why.
I want it to simply run through all the spreadsheets and check which of those have an X in cell A4 and (to start with) output yes or no in the console log but it keeps bugging.
Here's the code I've written so far:
It's outputting 14 lines of yes at the moment when only 3 sheets have the X in the cell.
I would be grateful if someone could point me in the right direction, I presume this is a pretty simple fix but I cant work it out from reading around on the web.
Thanks,
Archie.
Dec 22 2022 03:18 AM
Hi @ArchieSmith
I'm not an Office Script dev. + don't have access to the language with my subscription so no guarantee at all... What happens if you replace line #8 with:
if (rangeval = 'X'){
Dec 22 2022 05:08 AM - edited Dec 22 2022 06:46 AM
Hi @L z.
Unfortunately it does the same thing, 14 'yes'es.
It's an odd language that takes a lot from TypeScript and JavaScript from what I can work out.
Thanks for the help!
Dec 22 2022 06:45 AM
SolutionAfter 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');
}
}
)
}
Dec 22 2022 06:49 AM
Dec 22 2022 07:46 AM
Welcome @ArchieSmith & Thanks for providing feedback
+ Forgot to post: TypeScript Operators
Dec 22 2022 06:45 AM
SolutionAfter 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');
}
}
)
}