gunman69
asked on
Data validation in Excel - getting the Id, not Name
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
But you can also leave the order of the columns and use an Index/Match:
=index($C$1:$C$100,Match(A 1,$B$!:$B$ 100,0))
with ID in column B and Name in column C
cheers, teylyn
=index($C$1:$C$100,Match(A
with ID in column B and Name in column C
cheers, teylyn
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
=INDEX(Id,MATCH(A1,Name,0)
where Name refers to the name range and Id to the Id range
regards, barry
.....or what teylyn said.....:)
This will do what you want without having to switch the columns around.
=INDEX(MyRng,MATCH(A1,I8:I 10,0),1)
Kyle
Q-27343319-RevA.xlsx
=INDEX(MyRng,MATCH(A1,I8:I
Kyle
Q-27343319-RevA.xlsx
oops, sorry:) Refresh next time:)
@jppinto, the order of the columns is
ID | Name
not the other way round. Hence the suggestions for Index/Match.
ID | Name
not the other way round. Hence the suggestions for Index/Match.
....or use VLOOKUP without switching the columns...
=VLOOKUP(A1,IF({1,0},Name, Id),2,0)
regards, barry
=VLOOKUP(A1,IF({1,0},Name,
regards, barry
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
http://excel-user.blogspot.com/2011/07/negative-vlookupreturn-value-to-left-of.html
jppinto
And I thought swapping the columns around was a fairly harmless suggestion....:)
Barry,
I worry about you sometimes... :)
I worry about you sometimes... :)
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
[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
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
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
Are you supposed to take it with cider though??