VLOOKUP
Looks for a value in the leftmost column of a table and then returns a value in the same row from the specified column. By default, the table must be sorted in an ascending order.
Syntax
expression.VLOOKUP(arg1, arg2, arg3, arg4);
expression
- A variable that represents a ApiWorksheetFunction class.
Parameters
Name | Required/Optional | Data type | Default | Description |
---|---|---|---|---|
arg1 | Required | number | string | ApiRange | ApiName | The value to be found in the first column of the table. It can be a value, a reference, or a text string. | |
arg2 | Required | ApiRange | ApiName | A table of text, numbers, or logical values, in which data is retrieved. It can be a range of cells. | |
arg3 | Required | ApiRange | ApiName | number | The column number in the data table from which the matching value should be returned. The first column of values in the table is column 1. | |
arg4 | Optional | ApiRange | ApiName | boolean | A logical value that specifies whether to find the closest match in the first column (sorted in ascending order) (-true or omitted)\ or find an exact match (-false). |
Returns
number | string
Example
- Code
- Result
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("A1:C5");
worksheet.GetRange("D6").SetValue(func.VLOOKUP(3, range, 2, true));