Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Data validation in Excel - getting the Id, not Name

Posted on 2011-09-27
16
Medium Priority
?
231 Views
Last Modified: 2012-05-12
Here's what I want to do:
Let's say I have a named range with two columns:

Id     Name
1      One
2      Two
3      Three

For cell A1, I create a data validation of type List, so that the only acceptable values in A1 is One, Two or Three (i.e. any value in the "Name" column)

In cell A2, I make a reference to A1, so that it contains the corresponding Id of the selected value, i.e. 1 for One, 2 for Two, 3 for Three.

Is this possible WITHOUT MACROS? If the solution requires using a dropdown control instead of data validation, that is ok.

Thanks!
/Fredrik
0
Comment
Question by:gunman69
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +3
16 Comments
 
LVL 17

Accepted Solution

by:
andrewssd3 earned 2000 total points
ID: 36709137
It would be easier if you swapped the columns round in your named range (Name first then Id) so you could use VLOOKUP.  Say the named range is called Valid.  Then just set your validation in cell A1, and in A2 use the formula:
=VLOOKUP($A$1,Valid,2,FALSE)

Open in new window


This would only work correctly if the Name values were unique.  If not you would probably have to use a combobox control, which is probably overkill for this.
0
 
LVL 33

Expert Comment

by:jppinto
ID: 36709146
On cell A1 you can use a Data Validation list and on cell A2 you can use a VLOOKUP() function to get the corresponding ID.
0
 
LVL 50
ID: 36709159
But you can also leave the order of the columns and use an Index/Match:

=index($C$1:$C$100,Match(A1,$B$!:$B$100,0))

with ID in column B and Name in column C

cheers, teylyn
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 33

Expert Comment

by:jppinto
ID: 36709165
I've attached a sample file for you to check...

jppinto
Data-Validation-VLOOKUP.xlsx
0
 
LVL 50

Expert Comment

by:barry houdini
ID: 36709166
Without changing the data you can use INDEX and MATCH, i.e. in A2

=INDEX(Id,MATCH(A1,Name,0))

where Name refers to the name range and Id to the Id range

regards, barry
0
 
LVL 50

Expert Comment

by:barry houdini
ID: 36709173
.....or what teylyn said.....:)
0
 
LVL 12

Expert Comment

by:kgerb
ID: 36709189
This will do what you want without having to switch the columns around.

=INDEX(MyRng,MATCH(A1,I8:I10,0),1)

Kyle
Q-27343319-RevA.xlsx
0
 
LVL 12

Expert Comment

by:kgerb
ID: 36709197
oops, sorry:)  Refresh next time:)
0
 
LVL 50
ID: 36709204
@jppinto, the order of the columns is

ID     |   Name

not the other way round. Hence the suggestions for Index/Match.
0
 
LVL 50

Expert Comment

by:barry houdini
ID: 36709256
....or use VLOOKUP without switching the columns...

=VLOOKUP(A1,IF({1,0},Name,Id),2,0)

regards, barry
0
 
LVL 33

Expert Comment

by:jppinto
ID: 36709266
If the order of the columns is "inverted", you can use a "negative" VLOOKUP() function, like I propose here:

http://excel-user.blogspot.com/2011/07/negative-vlookupreturn-value-to-left-of.html

jppinto
0
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36709441
And I thought swapping the columns around was a fairly harmless suggestion....:)
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 36709702
Barry,
I worry about you sometimes... :)
0
 
LVL 50

Expert Comment

by:barry houdini
ID: 36709705
It's a good opening gambit.....!

[off topic alert]

...on the face of it VLOOKUP is easier to use but there's a case for using INDEX/MATCH even if the columns are the other way round. INDEX/MATCH allows you much greater flexibility, e.g. you can insert a column between Id and Name without causing the formula to fail (not the case with VLOOKUP)....you can see much more quickly which column the values are returned from (rather than having to count 47 columns with some VLOOKUPs) and you could, for instance, much more easily lookup a value in one row and return the value from the row above or below.

regards, barry
0
 
LVL 50

Expert Comment

by:barry houdini
ID: 36709796
Barry,
I worry about you sometimes... :)


Hello Rory - the doctor says that as long as I keep taking the medication I'll be OK in 10-15 years.....

barry
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 36709810
Are you supposed to take it with cider though??
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
Microsoft has changed the look and feel of Azure AD and Microsoft account sign-in pages so that you will have a more unified look and feel when moving between the two interfaces.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question