Edit

Share via


WorksheetFunction.VLookup(Object, Object, Object, Object) Method

Definition

Searches for a value in the first column of a table array and returns a value in the same row from another column in the table array.

public object VLookup (object Arg1, object Arg2, object Arg3, object Arg4);
Public Function VLookup (Arg1 As Object, Arg2 As Object, Arg3 As Object, Optional Arg4 As Object) As Object

Parameters

Arg1
Object

Lookup_value - the value to search in the first column of the table array. Lookup_value can be a value or a reference. If lookup_value is smaller than the smallest value in the first column of table_array, VLOOKUP returns the #N/A error value.

Arg2
Object

Table_array - two or more columns of data. Use a reference to a range or a range name. The values in the first column of table_array are the values searched by lookup_value. These values can be text, numbers, or logical values. Uppercase and lowercase text are equivalent.

Arg3
Object

Col_index_num - the column number in table_array from which the matching value must be returned. A col_index_num of 1 returns the value in the first column in table_array; a col_index_num of 2 returns the value in the second column in table_array, and so on.

Arg4
Object

Range_lookup - a logical value that specifies whether you want the VLookup(Object, Object, Object, Object) method to find an exact match or an approximate match:

Returns

Remarks

The V in VLookup stands for vertical. Use the VLookup method instead of the HLookup(Object, Object, Object, Object) method when your comparison values are located in a column to the left of the data that you want to find.

If Col_index_num is less than 1, the VLookup method generates an error.

If Col_index_num is greater than the number of columns in table_array, the VLookup method generates an error.

If Range_lookup is true or omitted, an exact or approximate match is returned. If an exact match is not found, the next largest value that is less than lookup_value is returned.

The values in the first column of table_array must be placed in ascending sort order; otherwise, the VLookup method may not give the correct value.

If Range_lookup is false, the VLookup method will only find an exact match. In this case, the values in the first column of table_array do not need to be sorted. If there are two or more values in the first column of table_array that match the lookup_value, the first value found is used. If an exact match is not found, an error is generated.

When searching text values in the first column of table_array, ensure that the data in the first column of table_array does not have leading spaces, trailing spaces, inconsistent use of straight ( ' or " ) and curly ( ‘ or “) quotation marks, or nonprinting characters. In these cases, the VLookup method may give an incorrect or unexpected value. For information about how to clean or trim values, see the Clean(String) and Trim(String) methods. When searching number or date values, ensure that the data in the first column of table_array is not stored as text values. In this case, the VLookup method may give an incorrect or unexpected value.

If range_lookup is false and lookup_value is text, then you can use the wildcard characters, question mark (?) and asterisk (*), in lookup_value. A question mark matches any single character; an asterisk matches any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (~) preceding the character.

Applies to