HLOOKUP

function HLOOKUP(
  arg1: any = null,
  arg2: number = null,
  arg3: number = null,
  arg4: boolean = null,
): number | string | boolean

Description

Looks for a value in the top row of a table or array of values and returns the value in the same column from a row you specify.

Parameters

arg1anydefault: null

Is the value to be found in the first row of the table and can be a value, a reference, or a text string.

arg2numberdefault: null

Is a table of text, numbers, or logical values in which data is looked up. Table_array can be a reference to a range or a range name.

arg3numberdefault: null

Is the row number in table_array from which the matching value should be returned. The first row of values in the table is row 1.

arg4booleandefault: null

Is a logical value: to find the closest match in the top row (sorted in ascending order) = TRUE or omitted; find an exact match = FALSE.

Returns

number | string | boolean

Try It

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

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

oWorksheet.GetRange("E1").SetValue("ID");
oWorksheet.GetRange("E2").SetValue(3);
oWorksheet.GetRange("F1").SetValue("Phone number");
var oRange = oWorksheet.GetRange("A1:C5");
oWorksheet.GetRange("F2").SetValue(oFunction.HLOOKUP("Phone number", oRange, 3+1));

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