Skip to content

Instantly share code, notes, and snippets.

@mutolisp
Last active September 19, 2016 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mutolisp/fa7a26cdf74ee4dca00a9e5f6b6c732f to your computer and use it in GitHub Desktop.
Save mutolisp/fa7a26cdf74ee4dca00a9e5f6b6c732f to your computer and use it in GitHub Desktop.
使用 Excel/LibreOffice VLOOKUP() 函數來查詢

假設我們有一份學名不含作者與學名含作者的對照表,其中 A1:A10 是學名不含作者,B1:B10 則是含作者。如果我們有一個清單是學名不含作者,但需要對照找出含作者的學名時該怎麼做呢?下方的表一和表二為範例資料:

表一、學名不含作者及含作者對照(1, 2, 3, ..., 10 代表 excel 中的列數,而 A, B, ..., D, E 代表欄位名稱)

A B
1 Antrophyum parvulum Antrophyum parvulum Blume
2 Bulbophyllum kuanwuense Bulbophyllum kuanwuense S. W. Chung & T. C. Hsu
3 Cyclobalanopsis stenophylloides Cyclobalanopsis stenophylloides (Hayata) Kudo & Masam. ex Kudo
4 Eleocharis acutangula Eleocharis acutangula (Roxb.) Schult.
5 Thladiantha nudiflora Thladiantha nudiflora Hemsl.
6 Huperzia squarrosa Huperzia squarrosa (G. Forst.) Trevis.
7 Triumfetta tomentosa Triumfetta tomentosa Bojer
8 Digitaria ciliaris Digitaria ciliaris (Retz.) Koeler
9 Tacca chantieri Tacca chantieri Andre
10 Lasianthus japonicus Lasianthus japonicus Miq.

表二、需要查詢的範圍(1, 2, 3, ..., 10 代表 excel 中的列數,而 A, B, ..., D, E 代表欄位名稱)

D E
1 需查詢不含作者的學名 查詢結果
2 Eleocharis acutangula
3 Thladiantha nudiflora
4 Huperzia squarrosa

我們將使用 vlookup(lookup_value, table_array, col_index, [range_lookup]) 這個函數來查詢學名含作者。 vlookup 第一個參數 lookup_value 代表待查詢的資料欄位範圍(例上表二中的 D1:D4);第二個則是查詢的表,可以是多個欄位範圍,例如表一中的 A2:B10;第三個則是查詢的表所要對應的欄位索引,假設表一中,我們希望透過 A 欄位的資料去查詢 B 欄位的資料,在 vlookup 選取 A2:B10 (共兩欄),B 欄位是選取範圍中的第二欄,此時 col_index 就填 2。最後 range_lookup 則是代表需要用精確搜尋(FALSE)或是近似搜尋(TRUE)。所以在表二中的 E2 欄,我們可以使用:

=VLOOKUP(D2:D4, A1:B10, 2, FALSE)

之後再把 E2 cell 向下拉到 E4 就可以完成此查詢。範例 excel 檔案請參見 excel_vlookup.xlsx。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment