List box to text box

Bigzippy

Board Regular
Joined
Jul 1, 2003
Messages
182
I have current Code:
Private Sub ListBox1_Change()
TextBox1.Value = ListBox1.List(ListBox1.ListIndex)

End Sub
Private Sub UserForm_Initialize()
ListBox1.RowSource = "a10:c20"
End Sub

I can't get my Textbox to show all 3 columns in the listbox selection, any ideas?

also I am ultimately trying to enter a list from a range (into listbox1) and edit the choosen line in the text box.Then when ok is hit edit the worksheet in the right spot. Am I on the right track?

Thank You
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Colo

MrExcel MVP,
Joined
Mar 20, 2002
Messages
1,456
Hi Bigzippy,

in that case, we have to specify the pvargColumn as follows.

Code:
Private Sub ListBox1_Change()
    With ListBox1
        TextBox1.Text = .List(.ListIndex, 0) & .List(.ListIndex, 1) & .List(.ListIndex, 2)
    End With
End Sub
 

Juan Pablo González

MrExcel MVP
Joined
Feb 8, 2002
Messages
11,959
Altough what Colo gave you should work, I really think that you should look at the builtin option of Data | Form, or if you need a more versatile one, look at J-Walk's site (www.j-walk.com/ss), for his Data Form... because after the user edits the Textbox, taking that info back to the listobx (and the sheet) can be a real mess.
 

Bigzippy

Board Regular
Joined
Jul 1, 2003
Messages
182
Thank you for both of your suggestions!
Colo-your code worked great, but is there a way to format the columns and set the widths or should I use a combobox for editing?
 

Colo

MrExcel MVP,
Joined
Mar 20, 2002
Messages
1,456
Bigzippy said:
Thank you for both of your suggestions!
Colo-your code worked great, but is there a way to format the columns and set the widths or should I use a combobox for editing?

You can specify the width of the Listbox with ColumnWidth. :biggrin:
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,102
Messages
5,768,102
Members
425,454
Latest member
khoro

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
Top