Drop down list returning another list element

gcefaloni

Board Regular
Joined
Mar 15, 2016
Messages
119
Hi guys,

I deal with a lot of weird identifiers that I can never remember and I was wondering if it would be possible to create a dropdown list that returns an element from an adjacent list. So if you refer to the list below as an example, let's say my drop-down list would be counterparty (names that I recognize) but when I actually click on one of those list elements, the adjacent element from the "CUID" or "BIC" column would populate (numbers I can never remember by heart) in its place. How would I go about doing that?

COUNTERPARTYCUIDBIC
NESSN987T754IN235E983SS
CASGRAINCAS9123365
CIBCC6I851B9C7
DESJ V213M78DMV1A4M4D6CAM1
LAURL75A66U9R1BL8C4MCA8M
NBFN9B323612S
RBCDOM7854ARB1D7S6CAT1

<colgroup><col><col><col></colgroup><tbody>
</tbody>
Thanks!!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Say you have the list ("COUNTERPARTY CUID BIC") in Sheet2 col A:C and you want to insert data in Sheet1 col A:C.
Use this code, put it in the code window of sheet1.
Everytime you insert data in sheet1 col A it will automatically insert the data (from the list) to the adjacent cell (col B:C).

Code:
[FONT=lucida console][COLOR=Royalblue]Private[/COLOR] [COLOR=Royalblue]Sub[/COLOR] Worksheet_Change([COLOR=Royalblue]ByVal[/COLOR] Target [COLOR=Royalblue]As[/COLOR] Range)
[COLOR=Royalblue]Dim[/COLOR] va

[COLOR=Royalblue]If[/COLOR] [COLOR=Royalblue]Not[/COLOR] Intersect(Target, Range([COLOR=brown]"A:A"[/COLOR])) [COLOR=Royalblue]Is[/COLOR] [COLOR=Royalblue]Nothing[/COLOR] [COLOR=Royalblue]Then[/COLOR]

    [COLOR=Royalblue]With[/COLOR] Sheets([COLOR=brown]"Sheet2"[/COLOR])
    va = .Range([COLOR=brown]"A2:C"[/COLOR] & .Cells(.Rows.Count, [COLOR=brown]"A"[/COLOR]).[COLOR=Royalblue]End[/COLOR](xlUp).Row)
    [COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]With[/COLOR]
    
    [COLOR=Royalblue]For[/COLOR] i = [COLOR=crimson]1[/COLOR] [COLOR=Royalblue]To[/COLOR] UBound(va, [COLOR=crimson]1[/COLOR])
        [COLOR=Royalblue]If[/COLOR] Trim(LCase(Target.Value)) = Trim(LCase(va(i, [COLOR=crimson]1[/COLOR]))) [COLOR=Royalblue]Then[/COLOR]
            Target.Offset(, [COLOR=crimson]1[/COLOR]) = va(i, [COLOR=crimson]2[/COLOR])
            Target.Offset(, [COLOR=crimson]2[/COLOR]) = va(i, [COLOR=crimson]3[/COLOR])
        [COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]If[/COLOR]
    [COLOR=Royalblue]Next[/COLOR]


[COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]If[/COLOR]
[COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]Sub[/COLOR][/FONT]
 
Upvote 0
Say you have the list ("COUNTERPARTY CUID BIC") in Sheet2 col A:C and you want to insert data in Sheet1 col A:C.
Use this code, put it in the code window of sheet1.
Everytime you insert data in sheet1 col A it will automatically insert the data (from the list) to the adjacent cell (col B:C).

Code:
[FONT=lucida console][COLOR=Royalblue]Private[/COLOR] [COLOR=Royalblue]Sub[/COLOR] Worksheet_Change([COLOR=Royalblue]ByVal[/COLOR] Target [COLOR=Royalblue]As[/COLOR] Range)
[COLOR=Royalblue]Dim[/COLOR] va

[COLOR=Royalblue]If[/COLOR] [COLOR=Royalblue]Not[/COLOR] Intersect(Target, Range([COLOR=brown]"A:A"[/COLOR])) [COLOR=Royalblue]Is[/COLOR] [COLOR=Royalblue]Nothing[/COLOR] [COLOR=Royalblue]Then[/COLOR]

    [COLOR=Royalblue]With[/COLOR] Sheets([COLOR=brown]"Sheet2"[/COLOR])
    va = .Range([COLOR=brown]"A2:C"[/COLOR] & .Cells(.Rows.Count, [COLOR=brown]"A"[/COLOR]).[COLOR=Royalblue]End[/COLOR](xlUp).Row)
    [COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]With[/COLOR]
    
    [COLOR=Royalblue]For[/COLOR] i = [COLOR=crimson]1[/COLOR] [COLOR=Royalblue]To[/COLOR] UBound(va, [COLOR=crimson]1[/COLOR])
        [COLOR=Royalblue]If[/COLOR] Trim(LCase(Target.Value)) = Trim(LCase(va(i, [COLOR=crimson]1[/COLOR]))) [COLOR=Royalblue]Then[/COLOR]
            Target.Offset(, [COLOR=crimson]1[/COLOR]) = va(i, [COLOR=crimson]2[/COLOR])
            Target.Offset(, [COLOR=crimson]2[/COLOR]) = va(i, [COLOR=crimson]3[/COLOR])
        [COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]If[/COLOR]
    [COLOR=Royalblue]Next[/COLOR]


[COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]If[/COLOR]
[COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]Sub[/COLOR][/FONT]

Thanks. I'll try to figure this out using vba as you are suggesting but I am not very familiar with it. Is there a way to do the same thing using Excel functions?
 
Upvote 0
Thanks. I'll try to figure this out using vba as you are suggesting but I am not very familiar with it. Is there a way to do the same thing using Excel functions?

Yes, but I only know a little about Excel formula, so maybe someone else here would help you with that.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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