Find Combobox value in range and show adjacent column value

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,422
Office Version
  1. 2016
Platform
  1. Windows
I have a Combobox on a Userform named ComboUser - It is populated from values in range L12:L50 like this;

Code:
Dim c As Range
ComboUser.Clear
With Worksheets("Setup")
For Each c In .Range(.Range("L12"), .Range("L" & .Rows.Count).End(xlUp))
If c.Value <> vbNullString Then ComboUser.AddItem c.Value
Next c
End With

What I need is for when it changes to populate another Combobox with the value from the same row but in column N. I need this to occur whenever ComboUser is changed and without the need for the press of a button.

The values in column L can be a mixture of text and numbers, text only or numbers only if this makes any difference.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Try this:-
The code is based on combobox1 and combobox2 in Userform1
Paste code at top of Userform Module.
Code:
Option Explicit
[COLOR=navy]Dim[/COLOR] combouser [COLOR=navy]As[/COLOR] ComboBox
Private [COLOR=navy]Sub[/COLOR] ComboBox1_Click()
    [COLOR=navy]Set[/COLOR] combouser = ComboBox1
    [COLOR=navy]With[/COLOR] combouser
        '[COLOR=green][B]Call second column of "Combouser" Combobox[/B][/COLOR]
        ComboBox2.Value = .List(.ListIndex, 1)
    [COLOR=navy]End[/COLOR] With
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Private [COLOR=navy]Sub[/COLOR] UserForm_Initialize()
[COLOR=navy]Dim[/COLOR] c [COLOR=navy]As[/COLOR] Range
[COLOR=navy]Set[/COLOR] combouser = ComboBox1
    combouser.Clear
    [COLOR=navy]With[/COLOR] Worksheets("Setup")
        [COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] c [COLOR=navy]In[/COLOR] .Range(.Range("L12"), .Range("L" & .Rows.Count).End(xlUp))
            [COLOR=navy]If[/COLOR] c.Value <> vbNullString [COLOR=navy]Then[/COLOR]
                combouser.AddItem c.Value
                '[COLOR=green][B]Place column "N" values in second column of Combobox[/B][/COLOR]
                combouser.List(combouser.ListCount - 1, 1) = c.Offset(, 2).Value
                '[COLOR=green][B]ComboBox2.AddItem c.Offset(, 2).Value 
                ' Not sure if you want/already have this data in combobox2.[/B][/COLOR]
            [COLOR=navy]End[/COLOR] If
        [COLOR=navy]Next[/COLOR] c
    [COLOR=navy]End[/COLOR] With
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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