TheLibreOffice.com

How to use VLOOKUP in LibreOffice Calc

Build an exact-match price lookup, copy it safely, use other sheets or files, and diagnose missing matches, wrong values and formulas displayed as text.

Find a match with VLOOKUP. A magnifier highlights the ID B04 in the first column.

To use VLOOKUP in LibreOffice Calc, put the lookup key in the first column of your source table and return a value from the same row. For the price table below, enter =VLOOKUP(F2;$A$2:$C$4;3;0) in G2: it finds the code in F2 and returns its price from column C. Keep the final 0 for product codes or IDs; it requests an exact match and works with an unsorted table.

I'd check a known code and a missing code before filling hundreds of rows. A lookup that returns a believable wrong price is more dangerous than one that clearly reports #N/A.

The examples use English function names, semicolon argument separators and Calc A1 references. If a pasted formula is rejected, check the formula settings before changing the lookup logic.

Return one price from a small table

Enter this sample data in A1:C4. The prices are teaching values with no currency attached; row 1 contains the headings.

RowA: CodeB: ItemC: Price
1CodeItemPrice
2P300Folder4
3P100Pen2
4P200Notebook6
  1. Enter P200 in F2. This is the value to find, separate from the source table.
  2. Select G2 and enter =VLOOKUP(F2;$A$2:$C$4;3;0). Keep the result outside A2:C4 so you don't overwrite the data or introduce a circular reference.
  3. Press Enter. Calc accepts a formula typed directly into a cell when it begins with an equals sign.
  4. G2 should show 6: P200 is in A4, and its price is in C4. Change F2 to P100; the result should become 2. Restore P200 before continuing.

VLOOKUP searches the first column of the range you supply, not every column on the sheet. Here it searches A2:A4. To find an item by its name instead, you would need a range beginning with the Item column, or a lookup with separate search and return ranges.

Read the arguments, then copy the formula

The syntax is VLOOKUP(Search criterion; Array; Index; Sorted range lookup). The fourth argument is optional in Calc, but writing it explicitly avoids the most common wrong-result mistake.

Argument in this exampleMeaning
F2The code to find. A cell reference lets you change the code without editing the formula.
$A$2:$C$4The source table. Its first column holds codes; its third holds prices. We leave the heading row outside the lookup range.
3The return column counted from the table's left edge: A is 1, B is 2, C is 3.
0Exact matching, equivalent to FALSE for this argument. There is no need to sort this code list.

The index is relative to the supplied table. A range D2:F20 also has three columns; index 3 returns F. It does not mean worksheet column C, and typing a column letter into this argument doesn't select that column.

Enter it through the Function Wizard

If separate fields are easier to follow, select the blank result cell G2 and open Insert > Function. In the Function Wizard, search for VLOOKUP, select it and click Next. Enter Search criterion: F2; Array: $A$2:$C$4; Index: 3; Sorted range lookup: 0. Check that the preview result is 6, then click OK.

Complete Calc Function Wizard with VLOOKUP selected, F2, $A$2:$C$4, index 3, exact-match 0, and a result of 6.
Enter the four VLOOKUP arguments and check the result preview before clicking OK. With P200 in F2, this table returns 6. Open the Function Wizard at full size.

Keep the source table fixed when filling down

Enter P100 in F3, copy G2 and paste it into G3. The copied formula should be =VLOOKUP(F3;$A$2:$C$4;3;0), returning 2. F2 moves to F3 because it is relative; the dollar signs keep the source range fixed.

Calc on Windows with G3 selected, Input line showing =VLOOKUP(F3;$A$2:$C$4;3;0), 2 in G3, 6 in G2 and the Code, Item, Price table in A1:C4
After you paste G2 into G3, the formula looks up F3 while the table stays $A$2:$C$4, so P100 returns its price of 2. Open the view at full size.

For a longer lookup list, fill the result formula down beside the keys, then inspect a row near the bottom as well as the first row. Without the dollar signs, A2:C4 would become A3:C5 one row down and gradually leave records behind. Absolute references prevent that copying offset; they can still adjust when referenced cells move or rows are inserted. Recheck both the range and the numeric return index after changing the table's layout.

Return the item and price from one key

To show two fields for the same code, keep P200 in F2 and use the original A1:C4 table. Enter 2 in H1 and 3 in I1, then enter this formula in H2:

=VLOOKUP($F$2;$A$2:$C$4;H$1;0)

Copy H2 to I2. H2 should show Notebook and I2 should show 6. The key and source table stay fixed; H$1 changes to I$1, so each output uses the return-column number above it. This applies the same relative and absolute reference rules as filling down. Each formula still returns one matching row.

Choose a code from a list

Once the lookup passes the checks below, you can make F2 easier to fill. Select F2, open Data > Validity > Criteria, choose Cell range under Allow, and enter $A$2:$A$4 in Source. Enable Show selection list and click OK. Choose P100 from the list: G2 should become 2. Restore P200 before continuing.

The validity criteria and selection-list settings control this input list. Keep its source range current when adding products. A validity rule can reject an absent code before VLOOKUP runs; to test missing-code behavior, use a working copy of the sheet and set F2’s Allow to All values before entering P999.

Use sorted matching for boundaries

Use 0 for a specific code, name or ID. Use 1 only when the task is to place a value into a band defined by ascending lower boundaries. TRUE, 1 or an omitted fourth argument selects sorted matching; Calc assumes the first column is already sorted. It doesn't sort it for you.

On an unsorted first column, the result can be unpredictable without producing an error. Changing the formula to 1 is therefore not a repair for a missing product code. Approximate matching is also not a spelling or similar-text search.

For a separate example, enter this table in J1:K4. Keep the boundaries numeric, ascending and distinct.

RowJ: Lower boundaryK: Band
1Lower boundaryBand
20Basic
3100Standard
4500Bulk

In a blank cell outside that table, =VLOOKUP(250;$J$2:$K$4;2;1) returns Standard. The selected boundary is the largest one at or below 250: 100. This is not the closest number by distance.

Check the edges when adapting a band table: 99 returns Basic, 100 returns Standard, 499 returns Standard and 500 returns Bulk. A value below the first boundary, such as −1 here, returns #N/A. A value above 500 remains in Bulk; add another boundary if your actual rule needs another band. When sorting a real table, move the complete rows together so each boundary keeps its correct label or rate.

Look up a table on another sheet

If the original A1:C4 product table is on a sheet named Prices in the same workbook, keep F2 and G2 on your working sheet. Enter this formula in G2:

=VLOOKUP(F2;Prices.$A$2:$C$4;3;0)

P200 still returns 6. For a sheet named Price List, use single quotes around the sheet name:

=VLOOKUP(F2;'Price List'.$A$2:$C$4;3;0)

The return index still starts at the left edge of the referenced range. If your real table starts in B and the answer is in E, use a B:E range with index 4, not 5. Its first column must contain the keys you are searching.

The dot is Calc A1 notation. With Excel A1 selected in Formula options, a sheet reference instead uses an exclamation mark, such as Prices!$A$2:$C$4. Check the selected syntax before treating an Excel-style reference as a mistake.

When the table is in another file

A separate workbook needs an external-document reference, not just a sheet name. Save the source file first, open both files, and build the reference from the destination formula: enter = in an empty cell, switch to the source workbook and select the required source cell. Calc creates the quoted file URL and sheet reference in the input line. Use that document-and-sheet prefix with the full absolute table range as VLOOKUP's second argument, keeping index 3 and final 0 for this example.

For example, if the saved source is C:\Data\Prices.ods and its sheet is Prices, the Calc A1 formula is =VLOOKUP(F2;'file:///C:/Data/Prices.ods'#$Prices.$A$2:$C$4;3;0). Use the prefix Calc created for your own file; this Windows example path is not a universal location.

Inspect the actual file path and source range after copying a formula into another workbook. To test the refresh, make copies of both workbooks and point the copied lookup formula to the copied source. Change a known price in that source copy and save it. Reopen the destination, accept the link update for a source you trust, then check that the lookup returns the new price. A correct value saved in a file is not proof that its external link still points to the intended source. If you need a self-contained working copy, put a copy of the source table on another sheet in the same workbook and use the same-file formula above. Keep that copied table current before relying on its prices.

Match the workbook's formula settings

On Windows or Linux, open Tools > Options > LibreOffice Calc > Formula. On macOS, open LibreOffice > Preferences > LibreOffice Calc > Formula. Calc's Formula options control reference syntax, function names and separators.

If Separators > Function is a comma, the opening example becomes =VLOOKUP(F2,$A$2:$C$4,3,0). Change the separators between arguments, leaving the range colon intact. If the interface uses localized function names, Use English function names lets you enter the English names shown here. Inspect the current settings first; there is no need to change a workbook configuration that already accepts your formulas.

Calc Separators group with Function set to a semicolon, Array column to a comma and Array row to a semicolon.
The Function field under Separators sets the character between arguments; the examples in this guide use a semicolon. Open the view at full size.

Fix an error or a convincing wrong value

#N/A: inspect the key and the first column

In exact mode, P999 returns #N/A because our sample contains no such code. If your key should exist, check that it lies inside the first column of the actual source range, including the last data row. Then inspect its stored type and characters.

A number and text that looks like a number can be different lookup values. In spare cells, use =ISNUMBER(F2) and =ISNUMBER(A4) to compare a numeric-looking lookup key and its expected source cell; substitute the row you actually expect. ISNUMBER and ISTEXT check the stored type. ISNUMBER is FALSE for both P200 cells in this tutorial because those codes are text; that is correct. A type mismatch matters when, for example, one side stores numeric 200 and the other stores text “200”.

Choose a consistent representation in a working copy. Keep meaningful leading zeros as text in account or product IDs: 00200 may be a different identifier from 200. Changing a displayed number format is not a dependable way to repair the stored values.

Look for stray spaces on both sides. =TRIM(F2) in a spare cell removes leading and trailing spaces and reduces repeated spaces between words. Inspect the cleaned value before using it; repeated interior spaces may be meaningful in some identifiers. Cleaning only F2 won't repair extra characters in the source key. Keep the original column and inspect imported invisible characters if ordinary space cleanup makes no difference.

Check literal keys and wildcard settings

Exact mode can still interpret text as a pattern. Inspect Tools > Options > LibreOffice Calc > Calculate, or the same Calc > Calculate page under LibreOffice > Preferences on macOS. Enable Search criteria = and <> must apply to whole cells when the entire identifier must match.

With wildcards enabled, * means any sequence of characters, ? means one character, and ~ escapes a special character. For a literal asterisk in a search criterion, use ~*; for a literal question mark, use ~?. For example, "P~*" searches for the literal code P* under wildcard matching. The documented wildcard rules apply with the final argument 0. If the workbook uses regular expressions, these wildcard escapes aren't its syntax; check that mode rather than pasting a wildcard fix blindly. Changing pattern settings can affect other formulas in the file.

Ordinary VLOOKUP text matching ignores case: P200 and p200 match. The Case sensitive checkbox in Calculate options does not change VLOOKUP's ordinary matching. If case distinguishes real IDs in your data, the basic formula here needs a different matching method.

Err:502: count the columns in the supplied range

A2:C4 has three columns. Requesting index 4 is outside it and produces Err:502; use 3 for Price. If you accidentally selected A2:B4, even index 3 is outside the range. Calc truncates a fractional index before checking its bounds, so use a deliberate whole-number index from 1 through the table's width.

Other symptoms need different checks. Calc's error-code reference distinguishes these failures:

SymptomCheck
Err:508Closing and opening parentheses, then the configured argument separator if the formula was pasted from elsewhere.
#REF!A missing or invalid cell, row or sheet reference.
#NAME?An unresolved function or range name, spelling and localized-name settings. Put literal text keys in straight double quotes.
Err:522 / circular referenceWhether the result cell is inside a referenced range or another formula loops back to it. Move the result outside the source table.
An “Invalid value” dialog rejects entrySelect the destination cell and inspect Data > Validity > Criteria. A list or other entry restriction can reject the input. This is separate from a calculated #N/A.

For the last case, Validity criteria describe the permitted values. Use a separate unrestricted output cell, or correct a restriction only when it no longer belongs there. Don't remove a useful validation rule from a whole table to repair one result cell.

A wrong value: check match mode, range and duplicates

Make the fourth argument explicitly 0 for a code lookup. Inspect the formula in the affected row for a shifted source range or the wrong return-column number. Confirm that the key and answer belong to the same record in the source.

If several rows have the same key, exact VLOOKUP returns the uppermost match. That is not necessarily the newest or correct price. Decide which record is authoritative before using the result; don't delete repeated IDs just to silence the lookup. Different rows may represent legitimate transactions or different dates. If you need every matching row, inspect or filter those records: a single VLOOKUP result doesn't combine them or total their values.

A formula is visible, or the result stops changing

If many cells display formulas, check LibreOffice Calc > View > Display > Formulas in Options or Preferences. Clear that box to display results instead of formulas.

For a single suspicious cell, =ISFORMULA(G2) in a spare cell checks whether G2 is a formula cell. If it is FALSE, inspect the input for an apostrophe before the equals sign or text formatting. Set the result cell to a normal number format and re-enter the formula beginning with =; changing the appearance alone doesn't re-enter it.

If G2 is a formula but changing F2 leaves an old result, inspect Data > Calculate > AutoCalculate. For a full refresh, Data > Calculate > Recalculate Hard recalculates all formulas. With an external source, also verify the source file and link; recalculation cannot correct a formula pointing to the wrong data.

Show a missing code without hiding other errors

After checking the keys, types and ranges, you can give an expected missing match a readable label:

=IFNA(VLOOKUP(F2;$A$2:$C$4;3;0);"Code not found")

On a narrow screen, scroll the longer formula boxes sideways to see the complete expressions.

P200 returns 6; P999 returns Code not found. IFNA handles #N/A specifically, so an invalid return index is still visible as an error. It can also catch #N/A coming from the matched source cell, so inspect that cell if the label appears for a known key.

I prefer that wording to a default zero for a price list. Zero can be a real price, and converting every error to zero would make missing records look valid. IFNA improves the presentation; it doesn't prove the lookup table is correct.

Choose another lookup when the table calls for it

VLOOKUP is a good fit when the key is the first column of a compact table and the result is in that column or to its right. To return a value to the left of the searched column, INDEX and MATCH let you specify the two ranges separately.

Using the original table, enter Notebook in H4. In an empty result cell, use:

=INDEX($A$2:$A$4;MATCH(H4;$B$2:$B$4;0);1)

The exact MATCH returns position 3 within B2:B4. INDEX then returns position 3 from A2:A4: P200, to the left of the Item column. Keep the two ranges aligned to the same records. This still returns one matching position; it isn't an all-results query.

XLOOKUP accepts separate search and result arrays and defaults to exact matching. It is available since LibreOffice 24.8. Choose it when the people editing the workbook have versions that support it. The XLOOKUP examples and older-version fallback let you check that choice on a copy of your table. For a basic code lookup shared with older spreadsheet versions, I'd keep the VLOOKUP formula with an explicit 0; it is easier to hand over without introducing a newer function dependency. The Calc vs Excel comparison covers the wider compatibility decision.

Check the saved lookup before handing it over

Before relying on the finished sheet, verify a known first-row key, a key farther down the source and an absent key. Inspect a copied formula near the bottom of your output list, and confirm that its source range includes every intended record. For band lookups, check values on both sides of each boundary.

Save a separate working copy, reopen it in the format you plan to share and repeat those checks. If another workbook supplies the data, verify that reference in the saved copy too. A sheet that still returns the expected values after a key change is a better handover than one that merely opens with yesterday's cached prices. The Calc guides cover the next tasks once the lookup is dependable.

Filed under Calc