Paintitblack3k
Paintitblack3k

Reputation: 75

Count spaces in NumberFormat with ExcelScript using OfficeScripts in Excel for Web

I have to count the spaces within in NumberFormat of each cell in column A. Here is an example NumberFormat:

"                       "@

I translated my VBA code into OfficeScripts ExcelScript (for Excel for Web) but it seems that the replace function doesn't removes the spaces:

sheet.getRange("A1").getNumberFormat().length - sheet.getRange("A1").getNumberFormat().replace(" ", "").length

Is there another option to count the spaces or did I something wrong with the replace function (other letters will be replaced correctly)

Upvotes: 0

Views: 146

Answers (1)

Paintitblack3k
Paintitblack3k

Reputation: 75

It's just the JavaScript syntax and the solution is:

sheet.getRange("A1").getNumberFormat().length - sheet.getRange("A1").getNumberFormat().replace(\s/g, "").length

Upvotes: 2

Related Questions