TextBox linked to a ComboBox?

C

capt

Is there a way to link a textbox to a combobox list?
I have a combobox1 on my userform that I want to be able to select a item on
that list and which in turn puts an associated item in textbox1.
To give you an example:
My list in sheet3("list")

A B
k5400 Travel
K5000 Physio
K5601 Surg
and so on.....ComboBox1 is linked to column "A"

If I select "K5400" in the combobox1 then I want "Travel" to come up in
textbox1

any ideas?
 
D

Dave Peterson

How about something like:

Option Explicit
Private Sub ComboBox1_Change()
With Me.ComboBox1
If .ListIndex < 0 Then
Me.TextBox1.Value = ""
Else
Me.TextBox1.Value = .List(.ListIndex, 1)
End If
End With
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
With Me.ComboBox1
.RowSource = Worksheets("Sheet1").Range("A1:B3").Address(external:=True)
.ColumnCount = 2
.BoundColumn = 1
.ColumnWidths = "22;0" 'hide the second column
End With
End Sub
 
C

Chris Lavender

Hi both
Wouldn't it be simpler just to set the LinkedCell property on both the
combobox and the textbox to the same cell; have the combobox ListFillRange
set to columns A and B; and have Column2 as the BoundColumn?

Best rgds
Chris Lav

capt said:
Thanks very much Dave,
It`s very complicated, but it works well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top