Forum Discussion
Comsubin
Nov 12, 2025Copper Contributor
Problem creating an Excel formula
I am contacting you because I am having trouble creating a formula to count names in an Excel spreadsheet. I have created a schedule in Excel in which there is usually one name per cell. The calcula...
Lorenzo
Nov 13, 2025Silver Contributor
TypeScript option
function main(
workbook: ExcelScript.Workbook,
names_range: string = "A2:A10",
result_cell: string = "B1"
) {
const activeSheet = workbook.getActiveWorksheet();
const names = activeSheet.getRange(names_range).getValues();
const RegNames = /[^/]+/g;
const CountNames = names.reduce((accum: number, row) => {
const value = row[0];
if (typeof value === "string" && value !== "") {
const matches = value.match(RegNames);
if (matches) {
accum += matches.length;
}
}
return accum;
}, 0);
activeSheet.getRange(result_cell).setValue(CountNames);
}