跳到主要内容

MATCH

Returns the relative position of an item in a range that matches the specified value in the specified order.

Syntax

expression.MATCH(arg1, arg2, arg3);

expression - A variable that represents a ApiWorksheetFunction class.

Parameters

NameRequired/OptionalData typeDefaultDescription
arg1Requirednumber | string | boolean | ApiRange | ApiNameThe value to be matched in the range. It can be a number, text, or logical value, or a reference to one of these.
arg2RequiredApiRange | ApiName | (number | string | boolean)[]A contiguous range of cells or an array containing possible lookup values.
arg3OptionalApiRange | ApiName | numberA number 1, 0, or -1 indicating which value to return.

Returns

number

Example

let worksheet = Api.GetActiveSheet();
let func = Api.GetWorksheetFunction();
let ids = ["ID", 1, 2, 3, 4, 5];
let clients = ["Client", "John Smith", "Ella Tompson", "Mary Shinoda", "Lily-Ann Bates", "Clara Ray"];
let phones = ["Phone number", "12054097166", "13343943678", "12568542099", "12057032298", "12052914781"];

for (let i = 0; i < ids.length; i++) {
worksheet.GetRange("A" + (i + 1)).SetValue(ids[i]);
}
for (let j = 0; j < clients.length; j++) {
worksheet.GetRange("B" + (j + 1)).SetValue(clients[j]);
}
for (let n = 0; n < phones.length; n++) {
worksheet.GetRange("C" + (n + 1)).SetValue(phones[n]);
}

let range = worksheet.GetRange("B1:B5");
worksheet.GetRange("D6").SetValue(func.MATCH("Ella Tompson", range, 0));