Using Vlookup in OpenOffice.org Calc

How to Use the VLookup Function in OpenOffice Calc

© Mark Alexander Bain

Vlookup is one of the most useful, but least understood, functions in OpenOffice Calc (and Microsoft Excel). This tutorial will show you how to use it effectively.

OpenOffice.org Calc is an incredibly useful tool whether it's used at home or in the office, and it makes an excellent replacement for the very popular (but relatively expensive) Microsoft Excel; both of these applications share many useful functions, and one of these functions is also one of the most useful, but least understood, functions - vlookup.

Using Columns of Data in OpenOffice Calc

Data in Calc (like any spreadsheet) is normally stored in columns, something like:

__|_____A_____|__B__|

1_|Gas________|_$100|

2_|Food(Home)_|_$500|

3_|Meals_______|_$100|

It's then possible for a user to use formulae to analyse the data in those columns:

4_|Total________|=SUM(B1:B3)

And then the user can see the results of that formula:

4_|Total________|_$600|

However, they can also make use of the data in other ways, for example, by using vlookup.

Using Vlookup to Find Data in a Calc Spreadsheet

The concept of vlookup is quite simple:

It, therefore, needs three pieces of information:

So if, for example, the data to be analysed is stored in the range H1 to J5:

__|_____H__|_I_|_J_|

1_|name____|age|gas

2_|Bill______|_45|500

3_|Fred_____|_21|750

4_|Jane_____|_23|100

5_|Mary_____|_56|257

then to look up the gas costs for Fred the following formula would be used:

=VLOOKUP("Fred";H2:J5;3)

and that would return the result 750.

The advantage of Using Vlookup

A key advantage of using vlookup is that it allows the user to look up different information very easily; for example the following will display Fred's details:

__|_A__|_B__|

1_|Name|Fred|

2_|Age_|=VLOOKUP(B1;H2:J5;2)

3_|Gas_|=VLOOKUP(B1;H2:J5;3)

and so if the contents of B1 are changed to 'Jane' then her details will be displayed instead of Fred's.

Optimizing Vlookup Usage

Although vlookup is very useful there are some things that can cause problems for the unwary user. The first consideration is one of speed - a sorted index is faster to search than an unsorted one, and so, where ever possible, the index should be sorted in descending order.

The second issue is much more of a problem: vlookup will always give an answer - even if it's the wrong one. For example, take:

=VLOOKUP("John";H2:J5;3)

Even though there is no 'John' in the data this will still return the result 750 (the actual result for 'Jane'); and:

=VLOOKUP("Zebedee";H2:J5;3)

will return 257 (the expected result for 'Mary'). The solution is to input a fourth variable and set this to 'False; for example:

=VLOOKUP("Zebedee";H2:J5;3;FALSE)

This time the result will be #N/A whenever a record cannot be found.

Conclusion

Although there are a couple of technicalities that can trip up a user, if these are taken account of, then vlookup is a very useful and versatile function that can make data manipulation much easier in OpenOffice Calc.


The copyright of the article Using Vlookup in OpenOffice.org Calc in Office/Business Software is owned by Mark Alexander Bain. Permission to republish Using Vlookup in OpenOffice.org Calc in print or online must be granted by the author in writing.





Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo