Permanent Reference Table

kelseye2eye

New Member
Joined
Apr 17, 2013
Messages
6
Hi!

I run multiple reports that give me data with the a country code rather than country name. I have a table of country codes and country names that I have referenced using a VLOOKUP, but was wondering what the most efficient way would be to save the Country Code table as an Add-On and run an automated replacement based upon the codes?

Any insight as to how to begin this process would be fantastic, as I'm stuck on a find/replace for each country code, but I know there has to be a better way!

Thanks!
Kelsey
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi Kelsey,

Here is what I would recommend.

In a new workbook (that will become an add-in workbook) insert this code in a new macro module:

Code:
Function CountryName(CountryCode As String) As String
   With Sheet1
      CountryName = .Application.WorksheetFunction.VLookup(CountryCode, .Range("CCtable"), 2)
   End With
End Function

Then on Sheet1 of the new workbook paste the table of Country Name vs Country Code such that the country code is in column A and the country name is in column B. If the country codes are not in alphabetical order, sort them.

Select the table, not including any header rows. Name the table "CCtable" by entering this name in the Name box just above cell A1.

Now you have available a user-defined function to look up country name. You can use it from a cell like this:

=countryname("SK")

which should yield "Switzerland".

You can then save this workbook as an add-in (.xlam) file, and then load it as an add-in in Excel to make the CountryName function available to other workbooks. Don't forget to save it as an Excel file (.xlsm) first so you retain a copy of it as once converted to an add-in you lose its source code.

Good luck!

Damon
 
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,982
Members
449,201
Latest member
Lunzwe73

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