COUNTA

COUNTA(args) → { number }

Counts a number of cells in a range that are not empty.

Parameters:

Name Type Description
args string | array | ApiRange

Up to 255 items, cell references, or ranges to count values. The first argument is required, subsequent arguments are optional.

Returns:

Type
number

Example

Copy code
builder.CreateFile("xlsx");
var oWorksheet = Api.GetActiveSheet();
var numbersArr = [45, 6, 8];
var stringsArr = ["Apples", "Oranges", "Bananas"]

// Place the numbers in cells
for (var i = 0; i < numbersArr.length; i++) {
    oWorksheet.GetRange("A" + (i + 1)).SetValue(numbersArr[i]);
}

// Place the strings in cells
for (var n = 0; n < stringsArr.length; n++) {
    oWorksheet.GetRange("B" + (n + 1)).SetValue(stringsArr[n]);
}

var oFunction = Api.GetWorksheetFunction();
var avg = oFunction.COUNTA(oWorksheet.GetRange("A1:C3"));
oWorksheet.GetRange("D3").SetValue(avg);
builder.SaveFile("xlsx", "COUNTA.xlsx");
builder.CloseFile();

Resulting document