VLOOKUP
function VLOOKUP(
arg1: any = null,
arg2: number = null,
arg3: number = null,
arg4: boolean = null,
): number | string | boolean
Description
Looks for a value in the leftmost column of a table and then returns a value in the same row from a column that you specify. By default, the table must be sorted in an ascending order.
Parameters
- arg1
any
null Is the value to be found in the first column of the table, and can be a value, a reference, or a text string.
- arg2
number
null Is a table of text, numbers, or logical values, in which data is retrieved. Table_array can be a reference to a range or a range name.
- arg3
number
null Is the column number in table_array from which the matching value should be returned. The first column of values in the table is column 1.
- arg4
boolean
null Is a logical value: to find the closest match in the first column (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]);
}
var oRange = oWorksheet.GetRange("A1:C5");
oWorksheet.GetRange("D6").SetValue(oFunction.VLOOKUP(3, oRange, 2, true));