Do you need to insert country flags in Excel cells?
This can help make geographic data reports more attractive and professional.
In today’s interconnected world, data is often global. It’s not uncommon to find spreadsheets filled with country-specific information or geo-specific datasets. Suppose you’re tracking international sales, analyzing global trends, or simply maintaining records with an international flavor, you might want to make your Excel sheets not just informative, but visually appealing as well.
One way to achieve this is by incorporating country flags into your Excel cells. These flags can serve as powerful visual cues, making your data more engaging and user-friendly. However, there isn’t any straightforward way to add country flags from a list of icons or flag images from the data library in Excel.
Instead, you can use various tools and functions of Excel to add country flags in Excel.
Read this Excel tutorial until the end as I show you various ways to insert regional flags in Excel using manual and automatic methods. Moreover, I’ll show advanced methods utilizing Excel VBA and Office Scripts so you can automate the process too. Let’s get started!
Reasons to Insert a Country Flag in Excel
Your primary motive for including country flags in an Excel worksheet is to enhance its visual qualities. Instead of just text names of countries, a flag helps you to attract the audience quickly.
Audiences from the related countries in your Excel worksheet will get emotionally connected with your reports or templates if they see the respective country flags.
Find below other major reasons to add country flags:
- Flags can serve as visual cues to quickly identify and associate data with specific countries, making your information more accessible.
- If you work with global data or conduct international business, flags can help you categorize and analyze information by country.
- In reports and presentations, flags can make your findings more visually appealing and easier to understand.
- Flags can provide cultural context, which is particularly useful when dealing with diverse audiences or multicultural data.
- Flags in educational spreadsheets can aid in geography lessons or cross-cultural studies.
- When you’re dealing with comparative data, such as country statistics, if you use flags you can make the differences and trends more apparent.
Microsoft Excel offers numerous tools, functions, and scripting capabilities that allow you to insert flags into your Excel workbooks without the need for an explicit ‘add flags’ button. Find below the smart ways you should try right now:
Add a Country Flag to an Excel Cell Manually
You can either manually place the flag image over the cell grid or within a cell.
Add Country Flag Over Cells
This method is just like inserting any image in Excel. However, in the current tutorial, I’ll show how you can insert the USA flag in a cell in an Excel cell. Now, you must source the flag yourself and download it as an image file, like JPEG or PNG. Here are the instructions you can follow:
- Run the Excel desktop app and open the workbook where you need to add country flags.
- Navigate to the specific cell within your worksheet where you want to insert the flag.
- Click on the Insert tab located in the Excel ribbon at the top of the application window.
- Within the Insert tab, locate and click on the Pictures option. This will open the Insert Picture From context menu.
- There, click on the This Device Option.
- On the Insert Picture dialog, navigate to the location where you’ve saved the flag image on your computer.
- Click the Insert button located at the bottom right corner of the dialog box.
Excel will insert the image instantly. However, it won’t resize the image to fit a cell or a range of merged cells. The flag will show up in its full resolution and size.
To resize it, click on the inserted flag. A set of points will show up on the edges of the image. Use those points to drag and resize the image. You can also drag by clicking the Ctrl key to resize the image from both sides at the same time.
Find above a screenshot of the resized country flag to the selected cell volume.
Add Country Flag In Cells
Microsoft shall introduce two new methods of importing images in Excel. Soon, you’ll find the Place in Cell and Place over Cells options in the Insert > Picture command of the Excel desktop app. You can experience it now by participating in the Microsoft 365 Insider program.
Here’s how to use this new Excel feature:
- Go to your worksheet, select the target cell for the country flag, and click the Insert tab.
- There, click on the Picture drop-down menu and hover the cursor over the Place in Cell option.
- Click on the This Device option in the overflow menu.
- Navigate to the country flag image you want to add using the Insert Tab dialog.
- Select the file and click Insert.
Excel will automatically insert the image and fit the Excel cell by keeping the aspect ratio. You don’t need to manually adjust the image file.
Insert a Country Flag in Excel Using Geography
The Data Types Geography tool in Excel is a hidden gem. It allows you to link names of places, cities, countries, regions, etc., to real-time online geography data. Then, you can extract related geographical data in another column, like population, gasoline price, area, GDP, and more. You can also use this feature to include the flag of the selected country or region.
Here’s how to use Data Types Geography to add country flags in Excel:
- Write down the name of the country in a cell of your Excel worksheet.
- Select the cell and click on Data > Data Types > Geography.
- Excel will take a moment to convert the text string into a geography data type and link it to online resources.
- A tiny Insert Data icon will show up above the selected cell.
- Click the Insert Data icon.
- On the context menu that shows up, scroll down to the Image list item and click on it.
- Excel shall insert the country flag right next to the selected cell.
- Excel shall also automatically adjust the country flag image to fit the cell.
Note: At the time of writing, the Data Types command in Excel is only available in Excel for the Microoft 365 desktop app and Excel for the web app. You can only use these Excel editions if you own a paid Microsoft 365 Business Standard or higher subscription.
Insert a Country Flag in Excel Using the IMAGE Function
If you want to insert country flags in Excel cells programmatically, you can use the IMAGE function. It allows you to add image source URL, image size, image height, and image width as Excel formula arguments.
Therefore, when you’re sourcing a country flag image from the internet, you can instruct Excel to resize the inserted image by adding height, width, and size arguments as numeric values.
This method is also specific to Excel for Microsoft 365 desktop and web app and requires a Business Standard subscription to use it. You should already have the feature if you’re accessing Excel as a part of a business or an organization.
Here’s how to utilize the IMAGE function:
Use IMAGE Function With Wikimedia URLs
- Select a cell where you want to insert a country flag.
- Then, enter the following formula inside the cell:
=IMAGE("https://upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/1280px-Flag_of_the_United_States.svg.png","USA",1)
- Hit Enter and you’ll get the USA image flag.
Here’s how you can customize the above formula:
- Put your own source of flag within the double quotes.
- Insert image alt text within double quotes.
- Enter a numeric
0
to insert the flag within the cell without changing the aspect ratio. - Alternatively, you can enter a numeric
1
to resize the image to fill the cell without conserving the aspect ratio.
When inserting the source URL, ensure the inserted hyperlink ends with any of these file extension codes: .PNG, .JPEG, .BMP, .GIF, .ICO, .WEBP, and .TIFF.
Use IMAGE Function With Flag CDN
You could find this challenging to source country flag URLs that end in a few selected file formats that Excel can render as an image. Hence, you can use the following CDN & API of flags by Flagcdn.com. This CDN link consists of 254 country flags in the PNG format.
https://flagcdn.com/48x36/ca.png
The above link will insert the country flag of Canada. To insert a different country flag change the URL code ca
to the alpha-2 code of the target country like us
, za
, uk
, etc. You must type the alpha-2 code for a country in small letters.
The steps to use the above link are the same as the steps mentioned in the above Wikimedia section.
Use the IMAGE Function and Flag Emojis
Follow these steps to insert country flags in Excel cells using emoji flags:
- Get emoji codes for the country flags you must insert in an Excel worksheet.
- You can visit Emojipedia to source emoji flags.
- Copy and paste the emoji code for a country flag in B3.
- Now, go to the target cell and enter the following formula in it:
=IMAGE("https://emoji.beeimg.com/"&B3&"/250/twitter")
- Hit Enter.
- Excel will add the country flag that you mentioned in cell B3.
If you need to insert many country flags, source the emoji codes for those country flags in a column. Then, copy and paste the above function in the adjacent cell for the corresponding country flags. You’ll effortlessly insert hundreds of country flags in a few seconds.
Insert Country Flag in Excel Using Excel VBA
Imagine the task of seamlessly integrating more than 100 country flag images from a local directory on your computer into an Excel worksheet. In this worksheet, the country names are organized neatly in a column.
Your objective is to automatically position the flag images right alongside their respective country names by expertly synchronizing the content from your designated folder with the entries in the worksheet column.
If you attempt to do this using any of the methods mentioned earlier you’d need to invest hours. Instead, you can use Excel VBA to automate the process. All you need to do is save the country flag images in the same name string as the country names that appear on the Excel worksheet.
If you’re ready with the flag images and the Excel worksheet, let’s begin with these steps:
- Press Alt + F11 to launch the Excel VBA Editor.
- Click the Insert button on the VBA Editor toolbar.
- Choose Module from the context menu that opens.
- In the new module, copy and paste the following Excel VBA script:
Sub InsertFlagImages()
Dim ws As Worksheet
Dim cell As Range
Dim flagPath As String
Dim flagFileName As String
Dim flagLeft As Double
Dim flagTop As Double
Dim flagWidth As Double
Dim flagHeight As Double
' Set the worksheet where you want to insert the flag images
Set ws = ThisWorkbook.Sheets("Sheet2")
' Loop through the country names in column A
For Each cell In ws.Range("A2:A8")
' Construct the full file path to the flag image
flagFileName = cell.Value & ".png"
flagPath = "C:\Users\CtOS\Downloads\Flags\" & flagFileName
' Check if the image file exists
If Dir(flagPath) <> "" Then
' Define the position and size of the image
flagLeft = cell.Offset(0, 1).Left
flagTop = cell.Offset(0, 1).Top
flagWidth = cell.Width
flagHeight = cell.Height
' Insert the image in the adjacent cell in column B
ws.Shapes.AddPicture flagPath, msoFalse, msoTrue, flagLeft, flagTop, flagWidth, flagHeight
Else
' If the image file does not exist, handle the error as you see fit
MsgBox "Flag image for " & cell.Value & " not found."
End If
Next cell
End Sub
- Click the Save button on the toolbar.
- Now, close the Excel VBA Editor interface.
Here’s how you can customize the above script:
- In code element
ThisWorkbook.Sheets("Sheet2")
, changeSheet2
to the exact worksheet name. - Change the cell range from
A2:A8
in the code elementws.Range("A2:A8")
to the actual cell range of your worksheet where you got country names. - In the code element
cell.Value & ".png"
, change the file extension.png
to the source file extensions like.jpg
,.jpeg
, etc. - For the code element
flagPath = "C:\Users\CtOS\Downloads\Flags\"
change the flag file location according to your own local directory.
To execute the script, press Alt + F8 and choose InsertFlagImages macro in the Macro dialog box. Hit the Run button to automatically insert the flag images.
Find above a screenshot of the result of the above Excel VBA script. This method isn’t available on Excel for the web or Excel online apps.
Insert Country Flag in Excel Using Office Scripts
If you wish to automate the insertion of country flags using Microsoft Power Automate and Excel, you need to use Office Scripts. This method is applicable to both Excel for the Microsoft 365 desktop and Excel for the web app.
Find below a script and the instructions to use it:
- Click the Automate tab.
- Inside the Scripting Tools block, click on the New Script button.
- Copy and paste this script inside the Code Editor:
function main(workbook: ExcelScript.Workbook) {
let selectedSheet = workbook.getActiveWorksheet();
// Paste string at cell range B2 on selectedSheet
selectedSheet.getRange("B2").setFormulaLocal("=IMAGE(\"https://flagcdn.com/48x36/us.png\",\"US\",0)");
// Set range B3:B5 on selectedSheet
selectedSheet.getRange("B3:B5").setFormulasLocal([["=IMAGE(\"https://flagcdn.com/48x36/gb.png\",\"GB\",0)"],["=IMAGE(\"https://flagcdn.com/48x36/fr.png\",\"FR\",0)"],["=IMAGE(\"https://flagcdn.com/48x36/ca.png\",\"CA\",0)"]]);
}
- Click the Save script button.
- Now, click the Run button.
Excel will automatically insert country flags for USA, GB, France, and Canada in the cell range B2:B5
by downloading flag images from the Flagcdn portal.
Here’s how you can customize the script:
- Change all instances of cell reference
B2
to another cell reference from which you want to start populating the country flags, likeC2
,D2
, etc. - Change the URL in the
IMAGE
function to insert different country flags than the ones inserted in this tutorial. - Modify the cell range
B3:B5
to a different range where you want to copy theIMAGE
function. For example,C3:C5
instead ofB3:B5
. - To insert more flags you need to copy and edit the
IMAGE
function for extra cells you want to add.
Conclusions
In the world of data, the ability to communicate information effectively is a priceless skill, and one way to do that is by adding visual elements to your spreadsheets. Adding flags to geographical data in Excel is one such skill.
In this guide, you learned various ways to insert flag images into cells in your Excel worksheet. You can use the manual image insert method if you do this occasionally. Or, you can automate the process by using methods like the IMAGE function, Data Types Geography function, Excel VBA, and Office Scripts.
Don’t forget to comment below mentioning your experience of using the above methods or to inform me of an easier and intuitive method that I might have missed.
0 Comments