lookup country name and return flag image to cell in Google Sheets

user1721451 picture user1721451 · Aug 2, 2017 · Viewed 7.2k times · Source

I have a country list of 245 countries.

Is there any way I can use a VLOOKUP in Google Sheets to import their respective flags?

I was thinking of potentially using a resource such as Wiki or http://www.theodora.com/flags/ but not sure if I can?

Answer

Max Makhrov picture Max Makhrov · Aug 2, 2017

Step 1. Get links

A1 = http://www.sciencekids.co.nz/pictures/flags.html

B1 = //@src[contains(.,'flags96')]

A3 = =IMPORTXML(A1,B1)

Step2. Use image function

B3 = =IMAGE(substitute(A3,"..","http://www.sciencekids.co.nz"))

Bonus. Country name:

C1 = ([^/.]+)\.jpg$

C3 = =REGEXEXTRACT(A3,C1)

enter image description here