Search functions: VLOOKUP or VLOOKUP and HLOOKUP or HLOOKUP

00Comment iconComment iconComment iconComment icon

Now we will see new types of functions in Excel or Spreadsheets: search functions! Such as VLOOKUP or VLOOKUP and HLOOKUP or HLOOKUP

Writer image

Übersetzt vonEditorial

Writer image

Überarbeitet vonEditorial

Edit Article

VLOOKUP Function

The VLOOKUP function means "vertical lookup". Its purpose is to look for some data or value in an array and find its corresponding match.

Syntax of the VLOOKUP Function

=VLOOKUP(lookup_value; table_array; col_index_num; range_lookup)

Where:

- lookup_value is the argument you want to provide as the basis for the search;

- table_array is the range where the search will be performed;

- col_index_num is the column from which you want to obtain the result, considering that columns are counted from the range stipulated in table_array

- range_lookup is the search precision, which can be exact or approximate to the desired value. It can therefore be TRUE or FALSE. If it is FALSE, it returns the value only if the lookup value exactly matches the table content.

Details to pay attention to:

-The function only looks to the right

- The function always returns the first match

- It is not case-sensitive. "A" and "a" are seen as the same letter.

Example

SalespersonRegionSales
Salesperson 1SouthR$ 87.925,00
Salesperson 2NorthR$ 129.887,00
Salesperson 3SoutheastR$ 12.908,00
Salesperson 4SouthR$ 99.087,00
Salesperson 5NortheastR$ 234.987,00
Salesperson 6NorthR$ 10.000,00
Salesperson 7SouthR$ 105.000,00
Salesperson 8MidwestR$ 1.876.098,00
Salesperson 9NortheastR$ 12.387,00
Salesperson 10SouthR$ 12.876,00
Salesperson 11SoutheastR$ 123.865,00
Salesperson 12MidwestR$ 128.543,00
Salesperson 13NorthR$ 987.000,00

1. How much did Salesperson 7 sell?

Solution

1. =VLOOKUP("Salesperson 7"; A1:D14; 3; FALSE) = R$ 105.000,00

HLOOKUP Function

The HLOOKUP function means "horizontal lookup". Its purpose is to look for some data or value in an array and find its corresponding match.

Syntax of the HLOOKUP Function

=HLOOKUP(lookup_value; table_array; row_index_num; range_lookup)

Where:

- lookup_value is the argument you want to provide as the basis for the search;

- table_array is the range where the search will be performed;

- row_index_num is the row from which you want to obtain the result, considering that rows are counted from the range stipulated in table_array

- range_lookup is the search precision, which can be exact or approximate to the desired value. It can therefore be TRUE or FALSE. If it is FALSE, it returns the value only if the lookup value exactly matches the table content.

Example

NameAgeSalary
Renato251500
Eduardo231800
Cristina361200
Bárbara381750
Vera221900
Evandro241600
Fátima312100
Carolina271990
Eloisa301300

1. What is the salary of the third person in vertical order?

Solution

1. =HLOOKUP("Salary"; A1:C10; 4; FALSE)

XLOOKUP Function

The XLOOKUP function was created to replace VLOOKUP, bringing more practicality and eliminating several limitations.

With it, you can look up values to the left or right, up or down, as well as allow clearer results when nothing is found.

Syntax of the XLOOKUP Function

=XLOOKUP(lookup_value; lookup_array; return_array; [if_not_found]; [match_mode]; [search_mode])

Where:

- lookup_value → value to be searched.

- lookup_array → range where the value will be searched.

- return_array → range from which the result will come.

- if_not_found (optional) → message or value returned if no match is found.

- match_mode (optional) → can be 0 (exact), -1 (next smaller), 1 (next larger), or 2 (wildcards such as * and ?).

- search_mode (optional) → allows you to define the search direction (from first to last or from last to first).

Advantages over VLOOKUP

- Allows you to look up values in any direction (not only to the right).

- Does not require the lookup column to be at the beginning of the table.

- Allows you to define custom messages if nothing is found.

- It is simpler to read and understand.

Example with the previous table

1. How much did Salesperson 7 sell?

Solution

=XLOOKUP("Salesperson 7"; A2:A14; C2:C14; "Not found")

- lookup_value: "Salesperson 7"

- lookup_array: A2:A14 (salesperson column)

- return_array: C2:C14 (sales column)

- if_not_found: "Not found"

Exercises

SalespersonRegionSales
JoãoSouth85500
MariaNorth120300
PedroSoutheast15200
AnaSouth98000
CarlosNortheast250000
JulianaNorth9800
RobertoSouth110000
BeatrizMidwest1890500
FernandaNortheast13500
RafaelSouth14200

1. What is Carlos's region?

2. What is Rafael's sales value?

3. Which salesperson made the highest sale?

4. What is the total sales of the salespeople in the South region?

NameAgeSalary
Eduardo261800
Carolina292100
Gustavo352500
Larissa403000
Fernanda241900
Thiago312700
Bruna282200
Marcos372900
Aline332600

5. What is Carolina's age?

6. What is Marcos's salary?

7. Who is the oldest employee?

8. What is the average salary of employees over 30 years old?

CodeProductCategoryUnit PriceStock
101MousePeripheralsR$ 80,00120
102KeyboardPeripheralsR$ 150,0085
103MonitorHardwareR$ 1.200,0045
104ProcessorHardwareR$ 2.500,0020
105Graphics CardHardwareR$ 3.800,0015
1061TB SSDStorageR$ 700,0050
1072TB HDDStorageR$ 500,0060
10816GB MemoryHardwareR$ 400,00100
109750W Power SupplyHardwareR$ 600,0040
110Gaming CasePeripheralsR$ 450,0025

9. What is the unit price of the product with code 104?

10. How many units are available of the product "16GB Memory"?

11. Which category does the product with code 110 belong to?

12. What is the most expensive product in the table?

13. What is the average stock of products in the "Hardware" category?