Create a Dynamic VLOOKUP function

Reading time: 2 minutes

How to build a Dynamic VLOOKUP with the MATCH function?

  • The challenge with the VLOOKUP function is to specify the column number from which you want to return data.
  • The idea is to replace this argument with the MATCH function
  • Like that, we will have a Dynamic VLOOKUP function

The third argument of VLOOKUP returns the column

Let’s consider a scenario where you have created a VLOOKUP function to return the State name based on the Employee ID.

VLOOKUP functions returns the State name
  • We search for the ID in cell C14
  • Our reference table is the Table tbl_Employee (A1:G12)
  • We want to return the 6th column (the State Name column)
  • Finally, 0 to perform an Exact Match

The result is correct. But if we want to return the employee’s name instead, we must manually change the third argument of the VLOOKUP function from 6 to 2.

This is why it’s more efficient to create a dynamic VLOOKUP, where the column index is linked to a dropdown list 😉

Dynamic Vlookup to retunr any column

How to create a Dynamic VLOOKUP

So, the idea is to replace the third argument with a MATCH function.

  • The MATCH function returns the position of an item in a list.
    • First argument: The text to search
    • Second argument: The array where to search the first argument
    • Third argument: The match mode (exact in this situation)

For instance, to return Wednesday’s position in the list of weekdays, we will write the following formula:

Match function to return the position of a day

In our scenario, we will use the MATCH function to find the position of a title column in the headers.

Position of the City column in the reference table

Then, we replace the third argument inside the original VLOOKUP function with the MATCH function, and the job is done.

The third argument is replaced by the match function

Add a dropdown list to select the column header.

The easiest way to select any column header is to build a dropdown list. Then you just have to select one of them to return the result for this column.

Add a dropdown list to select the column header

Practice with exercises

Practice the VLOOKUP function directly in the grid below.

VLOOKUP Exercise - Find a product's name, category and price

Look up a product's name, category or price from its reference in a 12-item catalog using VLOOKUP in exact-match mode — 3 guided steps.

=VLOOKUP( value , range , col_num , FALSE )

1 / 3

The reference in F2 is P003. In G2, write the VLOOKUP formula that finds the name of the product.

VLOOKUP Catalog — Q1 · 484

=VLOOKUP( value , range , col_num , FALSE )

2 / 3

The reference in F2 is P006. In G2, write the VLOOKUP formula that finds the category of the product.

VLOOKUP Catalog — Q2 · 485

=VLOOKUP( value , range , col_num , FALSE )

3 / 3

The reference in F2 is P004. In G2, write the VLOOKUP formula that finds the price.

VLOOKUP Catalog — Q3 · 486

Your score is

0%

Related articles

1 Comment

  1. Sein Hla Maung
    17/06/2018 @ 05:02

    Hi,

    Thank for your exercise file.

    Best Regards

    Sein Hla Maung

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Create a Dynamic VLOOKUP function

Reading time: 2 minutes

How to build a Dynamic VLOOKUP with the MATCH function?

  • The challenge with the VLOOKUP function is to specify the column number from which you want to return data.
  • The idea is to replace this argument with the MATCH function
  • Like that, we will have a Dynamic VLOOKUP function

The third argument of VLOOKUP returns the column

Let’s consider a scenario where you have created a VLOOKUP function to return the State name based on the Employee ID.

VLOOKUP functions returns the State name
  • We search for the ID in cell C14
  • Our reference table is the Table tbl_Employee (A1:G12)
  • We want to return the 6th column (the State Name column)
  • Finally, 0 to perform an Exact Match

The result is correct. But if we want to return the employee’s name instead, we must manually change the third argument of the VLOOKUP function from 6 to 2.

This is why it’s more efficient to create a dynamic VLOOKUP, where the column index is linked to a dropdown list 😉

Dynamic Vlookup to retunr any column

How to create a Dynamic VLOOKUP

So, the idea is to replace the third argument with a MATCH function.

  • The MATCH function returns the position of an item in a list.
    • First argument: The text to search
    • Second argument: The array where to search the first argument
    • Third argument: The match mode (exact in this situation)

For instance, to return Wednesday’s position in the list of weekdays, we will write the following formula:

Match function to return the position of a day

In our scenario, we will use the MATCH function to find the position of a title column in the headers.

Position of the City column in the reference table

Then, we replace the third argument inside the original VLOOKUP function with the MATCH function, and the job is done.

The third argument is replaced by the match function

Add a dropdown list to select the column header.

The easiest way to select any column header is to build a dropdown list. Then you just have to select one of them to return the result for this column.

Add a dropdown list to select the column header

Practice with exercises

Practice the VLOOKUP function directly in the grid below.

VLOOKUP Exercise - Find a product's name, category and price

Look up a product's name, category or price from its reference in a 12-item catalog using VLOOKUP in exact-match mode — 3 guided steps.

=VLOOKUP( value , range , col_num , FALSE )

1 / 3

The reference in F2 is P003. In G2, write the VLOOKUP formula that finds the name of the product.

VLOOKUP Catalog — Q1 · 484

=VLOOKUP( value , range , col_num , FALSE )

2 / 3

The reference in F2 is P006. In G2, write the VLOOKUP formula that finds the category of the product.

VLOOKUP Catalog — Q2 · 485

=VLOOKUP( value , range , col_num , FALSE )

3 / 3

The reference in F2 is P004. In G2, write the VLOOKUP formula that finds the price.

VLOOKUP Catalog — Q3 · 486

Your score is

0%

Related articles

1 Comment

  1. Sein Hla Maung
    17/06/2018 @ 05:02

    Hi,

    Thank for your exercise file.

    Best Regards

    Sein Hla Maung

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *