Forum Discussion
BRANDON1385
Mar 27, 2024Copper Contributor
SCRIPT EXCEL
1. First start with "ORANGE" -worksheet-, but I need switch to "BLACK" -worksheet-, to replace more information. I tried with a) let dataWorksheet = workbook.getWorksheet("BLACK"); dataWor...
rachel
Mar 28, 2024Iron Contributor
Why can't you just loop?
function main(workbook: ExcelScript.Workbook) {
let sheets = workbook.getWorksheets().filter(q => q.getName() === 'ORANGE' || q.getName() === 'BLACK');
sheets.forEach(q => {
q.getUsedRange().replaceAll("A.REY", "A. REY", { completeMatch: false, matchCase: false });
});
}
SergeiBaklan
Mar 28, 2024Diamond Contributor
Nice solution. I'd only not to hardcode sheet names within formula, something like
function main(workbook: ExcelScript.Workbook) {
const names = ["BLACK", "ORANGE"]
workbook.getWorksheets()
.filter( q => names.includes(q.getName()))
.map( w => w.getRange("H:H").getUsedRange()
.replaceAll("A.REY", "A. REY",
{ completeMatch: false, matchCase: false }
)
)
}
Also better the range name to move outside if only only we won't apply to entire used range within the sheet.
- rachelMar 29, 2024Iron ContributorThank you so much! that is much cleaner. When I code in c#, I relied heavily on the intellisense of JetBrain Rider to automatically convert my for loop to linq etc. so when I started to write this script, I felt so good because the intellisense is much better than I expected and colour theme is dark, but then I felt handicapped when I realised it won't automatically help me refactor my code. so I actually ended up spending half of my morning googling the translation from C# Linq to Javascript to write this.
- SergeiBaklanMar 29, 2024Diamond Contributor
Lot of technologies involved. C#, Rider, Linq, TypeScript and finally Excel. Impressive!
- rachelMar 29, 2024Iron ContributorMost IT professionals can grasp the basics of a new programming language within days...but it just take lots of experience to develop a fine taste in Excel. Probably because there is no shortcut such as intellisense or debugging tools for those excel formulas