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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
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
 
Upvote 0
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.
 
Upvote 0
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?
 
Upvote 0
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:
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,305
Members
449,079
Latest member
juggernaut24

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