COUNTIFS

function COUNTIFS(
  arg1: ApiRange = null,
  arg2: number | string = null,
  arg3: ApiRange = null,
  arg4: number | string = null,
): number

Description

Counts a number of cells specified by a given set of conditions or criteria.

Parameters

arg1ApiRangedefault: null

The first range of cells to count nonblank cells.

arg2number | stringdefault: null

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

arg3ApiRangedefault: null

Up to 127 additional ranges of cells to count nonblank cells. This argument is optional.

arg4number | stringdefault: null

Up to 127 additional conditions in the form of a number, expression, or text that define which cells will be counted.

Returns

number

Try It

var oWorksheet = Api.GetActiveSheet();
var oFunction = Api.GetWorksheetFunction();
var buyer = ["Buyer", "Tom", "Bob", "Ann", "Kate", "John"];
var product = ["Product", "Apples", "Red apples", "Oranges", "Green apples", "Oranges"];
var quantity = ["Quantity", 12, 45, 18, 26, 10];

for (var i = 0; i < buyer.length; i++) {
   oWorksheet.GetRange("A" + (i + 1)).SetValue(buyer[i]);
}
for (var j = 0; j < product.length; j++) {
   oWorksheet.GetRange("B" + (j + 1)).SetValue(product[j]);
}
for (var n = 0; n < quantity.length; n++) {
   oWorksheet.GetRange("C" + (n + 1)).SetValue(quantity[n]);
}

var oRange1 = oWorksheet.GetRange("B2:B6");
var oRange2 = oWorksheet.GetRange("C2:C6");
oWorksheet.GetRange("E6").SetValue(oFunction.COUNTIFS(oRange1, "*apples", oRange2, "45"));

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).