Dependent textbox in form

ndendrinos

Well-known Member
Joined
Jan 17, 2003
Messages
1,694
My sheet (Authors) is set up like this:

Column B........Column C
..Toronto........Canada....
..Paris............France....

In Userform5 I have a listbox from which I choose (let us say) Toronto
On the same form in TextBox1 I want to see Canada

Need coding just for the TextBox
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi,

This should work for you, right click on your listbox and then 'view code' and then copy and paste the following.

You will probably have to alter the Listbox & Textbox names according to your own and alter the first number in brackets to your necessary column.

Code:
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
TextBoxCounrty = Me.ListBox1.Column(1, Me.ListBox1.ListIndex)
End Sub

HTH
 
Upvote 0
Hello shudder and thanks for your solution.
I cannot get it to work and wonder if you have any named ranges in there.
My listbox is: ListBox1 (where i choose from)
and I need to see the result in TextBox1 (from column3 in sheet "Authors"
 
Upvote 0
Actually yes, the project I took that from does use named ranges
 
Upvote 0
The code I provided is generic, all I have done is set the 'RowSource' property of the listbox in form design mode to my named range.

Although this can be done by VBA by using this line:

Code:
Listbox1.RowSource = Sheets("Sheet1").Range("Name of Your Range")
 
Upvote 0

Forum statistics

Threads
1,217,023
Messages
6,134,070
Members
449,858
Latest member
mangjuan

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