I managed to make a relatively logical and functional script that takes all empty cells in a column, and then one by one compares a list (separate table) for matching words. The problem is that is so unbelievably inefficient/slow and memory intesive, in practice it's not useful.
function main(workbook: ExcelScript.Workbook) {
let transactionsTable = workbook.getTable("table_transactions");
let emptyCatCells = transactionsTable.getColumnByName("category").getRange().getSpecialCells(ExcelScript.SpecialCellType.blanks)
let lookupWords = workbook.getTable("table_autoCatReference").getColumnByName("lookupWord").getRange().getValues()
if (emptyCatCells) {
// Loop through areas
for (let i = 0; i < emptyCatCells.getAreas().length; i++) {
let areaBlankCategory = emptyCatCells.getAreas()[i];
// Loop through cells
for (let j = 0; j < areaBlankCategory.getCellCount(); j++) {
let descEmptyCat = areaBlankCategory.getCell(j, -1)
for (let lookupWord of lookupWords) {
if (descEmptyCat.getText().includes(lookupWord)){
areaBlankCategory.getCell(j, 0).setValue("FOUND")
} else {
}
}
}
}
} else {
console.log("No blank cells")
}
}
So I have a table_transactions with columns description and category. Also I have a table_autoCatReference with lookupWord and matchedCategory
For every row that has an empty category, I want to lookup lookupWords for a match in the cell for the description of the corresponding empty category. If a match is found, then place the matchedCategory (did not get to implement this yet, for now its a static string) for the lookupWord in the empty cell of category (in the first table)
I sort of got somewhere with my script but in sure it's very questionable. I would be very interested in learning about superior ways of thinking and implementing this idea. Thank you.
There are some changes to improve the efficency
categoryanddescriptioninto arraylookupWordintoDictionarydesValues[i][0] in dictCatecategorycol all at once