Help with Converting Country Codes into Region Names

sticks

New Member
Joined
Dec 28, 2011
Messages
2
Hello,
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I receive a weekly spreadsheet containing worldwide sales data. For each country in which a product of ours is sold, that country is represented by their two letter country code in the spreadsheet (ex. US, CA, GB, etc.). The team, to which I pass along the data, is just concerned with the total sales numbers for the particular world regions (ex. North America, Europe, etc.) so I need to find some way in which to convert the country code to the applicable region name and then place that region name in a separate column. I assume this would consist of creating a script with two arrays; one array containing the country codes and the other containing the region names?
<o:p></o:p>
<o:p></o:p>
In summary, this is what I’d be looking to do:
<o:p></o:p>
<o:p></o:p>
1. Select the column containing the country codes. In this case, the country codes are found in column E.
<o:p></o:p>
2. Call on some sort of function to convert the country code to the region name and place the region name in column F – on the same row, obviously.
<o:p></o:p>
3. For any countries which appear in the spreadsheet, but not in the array, the region name will be presented as a blank cell.
<o:p></o:p>
<o:p></o:p>
Hope this makes sense.
<o:p></o:p>
<o:p></o:p>
Unfortunately, I’m not a programmer by any means so specific instructions/code will certainly be appreciated. To make things easy, an example can be used with just “US” converting to “North America” and “GB” converting to “Europe”. “US” and “GB” would be found in cells E2 and E3 respectively and their corresponding region names would be placed in F2 and F3.
<o:p></o:p>
<o:p></o:p>
I’m sure something like this exists many times over but I haven’t been able to come across it in my searches. Seems that all I came across were those which converted something you typed rather than selected from already existing data.
<o:p></o:p>
<o:p></o:p>
Thanks in advance to whomever can help with this.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hello sticks, and Welcome to Mr. Excel!
The function you want in Excel is called VLOOKUP.
To use it with your data, create a list with each country in one column, and the corresponding region in the adjacent column. Since you'll be using the country to find the region, put the countries in a column to the left of the region column (VLOOKUP looks in the first column to find a match, then returns the value in a specified column).
For example:
<TABLE style="WIDTH: 131pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=175 border=0><COLGROUP><COL style="WIDTH: 48pt" width=64><COL style="WIDTH: 83pt; mso-width-source: userset; mso-width-alt: 4059" width=111><TBODY><TR style="HEIGHT: 15pt" height=20><TD class=xl63 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 48pt; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" width=64 height=20>USA</TD><TD class=xl63 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext; WIDTH: 83pt; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent" width=111>North America</TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl63 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>CA</TD><TD class=xl63 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">North America</TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl63 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>MX</TD><TD class=xl63 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">North America</TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl63 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>BR</TD><TD class=xl63 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">South America</TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl63 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>CH</TD><TD class=xl63 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">South America</TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl63 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>GB</TD><TD class=xl63 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">Europe</TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl63 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>FR</TD><TD class=xl63 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">Europe</TD></TR><TR style="HEIGHT: 15pt" height=20><TD class=xl63 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 15pt; BACKGROUND-COLOR: transparent" height=20>DE</TD><TD class=xl63 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext; BORDER-BOTTOM: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent">Europe</TD></TR></TBODY></TABLE>
I usually put this on another worksheet in my workbook so that it's not in the way of the main data that I'm interested in. So, for purpose of example, let's say that this table is on Sheet2, cells A1:B8.
In column F of the row with your first country data, enter the following formula:
Code:
=IFERROR(VLOOKUP(E1,Sheet2!$A$1:$B$8,2,0),"")
Change E1 to the cell with your first country code.
Change Sheet2 to the name of the worksheet with the region lookup table. Be sure to leave the "!" after the name. If there are spaces in the sheet name, the sheet name will need to be enclosed in single quotes (e.g. 'Region Lookup Table')
Change the $A$1:$B$8 reference to the complete range of the region lookup table.
Drag this formula down to the rest of the rows with countries. It should populate with the proper region if there's a named region for that country, or blank if no region has been established.
Hope that helps,
 
Upvote 0
Cindy - that worked perfectly! Thanks so much!

Just curious (and certainly no worries if you don't have the time to reply) but what do the '2,0),"")' represent in the remainder of the code? Asking because hopefully that will help me to understand the solution better and apply it to future problems.

Thanks again and Happy New Year!
 
Upvote 0
You're welcome, and thanks for the feedback!
In VLOOKUP, the first argument is what you're looking for, the second is the range that includes both what you're looking for and what to return when it's found, the third one is which column of that range has the answer (2 means the colimn next to the one with the lookup values), and the last one (the 0) tells Excel that you only want an exact match. You can find more detail in Excel's help.
 
Upvote 0

Forum statistics

Threads
1,223,718
Messages
6,174,077
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top