PPRuNe Forums - View Single Post - Excel vLookup function - I think !
View Single Post
Old 10th Apr 2008, 12:57
  #2 (permalink)  
MacBoero
 
Join Date: Jan 2008
Location: London, England
Age: 56
Posts: 300
Likes: 0
Received 0 Likes on 0 Posts
As a small example:

In a blank Excel WorkBook, go to Sheet2.
In A1 put a column header "Airport Code"
In A2 put a column header "Airport Name"
In A3 put a column header "Runway Length"

You can add as many columns as you like, but this will suffice.

Put a few codes, in column A, I just put in AAA, AAB, AAC and so on for 10 values.

Put the names and runway lengths, I just used "Airport 1", "Airport 2", etc, and 1001, 1002, 1003 for the length. That way I can see if the function is working correctly.

So had something like

A B C
1 Airport Code Airport Name Runway Length
2 AAA Airport 1 1001
3 AAB Airport 2 1002
4 AAC Airport 3 1003
5 AAD Airport 4 1004
6 AAE Airport 5 1005
7 AAF Airport 6 1006
8 AAG Airport 7 1007
9 AAH Airport 8 1008
10 AAI Airport 9 1009
11 AAJ Airport 10 1010


Now select the data cells from the first column, in this case from AAA to AAJ. Near the top left of the Excel window, there is the coordinates box, it will have "A2" in this example, or the coordinate of the top left box of the selected region. Click in here and type "AirportCodes", note no spaces!

Now select all three columns of the dataset, i.e. A2, down to C11. Give this set a name of "AirportCodeDB"

This creates a named data set for use later.

Go to Sheet1

Click any cell you like. We will use this one for the airport code drop down list. Click "Data" in the menu bar, and select "Validation...". In the pop-up window, set "Allow" to list, and set the source for the list to "=AirportCodes", again no spaces and don't forget the equals sign. Normally you would be able to drag and select the range of values for the list directly from the worksheets. However, for validation, this doesn't work when the list is in another worksheet. This is why the list data set has been given a name, because these named sets are usable across all sheets. Silly huh!

Anyway, OK the validation pop-up, and you should see a drop down arrow to the right of the field you had selected, clicking on this will reveal the list and you can simply click a value.

Right...

In the next field to the right, type "=vlookup("
Now click the cell with the dropdown list, in my case I had chosen A3.
Then type ",AirportCodeDB,2)" and hit enter.
If you click that cell now you should see something similar to this...
=VLOOKUP(A3,AirportCodeDB,2)
Where A3 will be perhaps different in your case.
In the next cell over do the same except the last digit is 3, i.e.
=VLOOKUP(A3,AirportCodeDB,3)

Now change the drop down value, and what you should find is that when you change the drop down, the corresponding Airport Name and Runway Lengths we put into Sheet2, should instantly appear in their respective cells alongside.

One thing to watch out for, is that if the dropdown box is empty, or the VLOOKUP doesn't find an entry, you may find that the VLOOKUP simply returns the last entries in the list, i.e. "Airport 10" and "1010".

Good luck!
MacBoero is offline