COUNTIF

function COUNTIF(arg1: ApiRange = null, arg2: number | string = null): number

Description

Counts a number of cells within a range that meet the given condition.

Parameters

arg1ApiRangedefault: null

The range of cells to count nonblank cells.

arg2number | stringdefault: null

The condition in the form of a number, expression, or text that defines which cells will be counted.

Returns

number

Try It

var oWorksheet = Api.GetActiveSheet();
var oFunction = Api.GetWorksheetFunction();
var fruits = ["Apples", "Oranges", "Bananas"];
var numbers = [45, 6, 8];

for (var i = 0; i < fruits.length; i++) {
   oWorksheet.GetRange("A" + (i + 1)).SetValue(fruits[i]);
}
for (var j = 0; j < numbers.length; j++) {
   oWorksheet.GetRange("B" + (j + 1)).SetValue(numbers[j]);
}

var oRange = oWorksheet.GetRange("A1:B3");
oWorksheet.GetRange("D3").SetValue(oFunction.COUNTIF(oRange, "*es"));

Get Help

  • If you have any questions about ONLYOFFICE Docs, try the FAQ section first.
  • You can request a feature or report a bug by posting an issue on GitHub.
  • You can also ask our developers on ONLYOFFICE forum (registration required).