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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Colo

MrExcel MVP,
Joined
Mar 20, 2002
Messages
1,659
Office Version
  1. 2016
  2. 2003 or older
Platform
  1. Windows
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

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.
 
Upvote 0

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?
 
Upvote 0

Colo

MrExcel MVP,
Joined
Mar 20, 2002
Messages
1,659
Office Version
  1. 2016
  2. 2003 or older
Platform
  1. Windows
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,187,179
Messages
5,962,057
Members
438,578
Latest member
MrJimC

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