Drop-down list Question

On a separate worksheet I have a vlookup table that has columns like these:

CountryID     CountryName
---------     -----------
   1          United States
   2          Canada
   3          China

Open in new window

I've seen examples that show how to display the drop down and see the country names themselves, but I would like to know how to insert the CountryID instead of the CountryName in the cell. So when a user clicks the dropdown on the cell, they will see the country names listed, but when they select "United States" the CountryID of "1" is added to the column.

Is this possible? Are there any exampels of this anywhere?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

See attached example, using MS Forms Drop Down.  if you right click the drop down, you can format the control, set a range equal to what's displayed, and also a cell link.  The cell link will get a number from 1-X in order of the drop down.

Martin LissOlder than dirtCommented:
Use the Combo1.ItemData(index) value.

For example Range("A1").Value = Combo1.Itemdata(2)
In the attached, using a data validation list below the drop down example, you can select any country and have that country's ID displayed using an INDEX/MATCH function.


JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Here is a simple example using an ActiveX ComboBox.  The key things are, look at the properties of the combobox - make ColumnCount = 2, then ColumnWidths 0; to make the first column hidden.  Keep BoundColumn as 1 - that says use the first column as the result.  ListFillRange is set to 'Countries', a named range that includes the id and name columns for the countries, and finally LinkedCell is set to E1 to say put the result in E1 (ie this is where the bound column value will go.countries.xlsx

Hope this helps

greddinAuthor Commented:
To dlmille, when using a form like this how would I use this form control down the entire column. On my first worksheet when I'm selecting the country, there will be a long list of rows where I have to select the country. Your example is almost what I envision, but is there a way to do this with a vlookup function?
What type of drop down do you want to use?  A DV list or a Drop down?  See attached last example, and I can expand from there.

A DV list is easy to propagate down a column.  A control takes up memory and can get messy.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
See this last example, where you have a larger column of countries to select.  Its easy enough then to use the lookups to find the country ID.

Looks like everyone was busy while I was typing my answer :)  If you want a whole column, the best options would be Dave's data validation solution, as this is easy to apply to multiple cellls - you could addd the controls, but that would require VBA and be quite clumsy and difficult to extend
greddinAuthor Commented:
Thanks Dave for the newer example, looks like the data validation list is what I wanted. This is perfect. Thanks for showing me an example.
greddinAuthor Commented:
Thanks again!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.